Friday, February 23, 2018

Re: UUIDs eventually choke as primary key

Adding details I seem to have left out. The id is defined like this:
id = models.UUIDField(primary_key=True, default=uuid.uuid1, editable=False)
and I'm running on PostgreSQL.
I'm pretty sure I never create a row without already having the key.

On Monday, February 12, 2018 at 1:00:53 PM UTC-8, M Mackey wrote:
I've run into a strange issue with using a UUID as primary key, and I'm hoping we can either verify this is a bug, or figure out what I've done wrong.

I've got a core model object with a UUID for it's primary key. (Generated external to this system, thus using that for when additional information comes in.) And there are other model objects referencing it. Normally everything runs fine. But after a while, web pages that have been running fine start telling me that the UUID isn't valid (even though it is). (Sorry I don't have a copy of the error at this moment, I'll post here when it happens again.) I know it's not a simple coding error, because I can simply restart Apache and everything is fine again. And these aren't POST responses or anything complex like that. It occurs on a simple listing page.

When I dig into the exceptions, I see something that seems contradictory. It looks like the UUID constructor has been called with an instance of a UUID (it says type UUID doesn't have method 'replace'). But it doesn't seem like that should be possible because the code that calls that constructor first checks the type. (See django/db/models/fields/__init__.py - UUIDField.to_python)
So it's a double head scratcher. Once this problem crops up, I have to restart the web server (but then it's okay for a while). And the errors it gives me don't make much sense.
I don't know what kind of caching problem it could be - I haven't enabled any of the available caching systems. Also doesn't seem to crop up (at least not as often) in the built in dev test server.

Anyone seen this, or have any ideas?

Thanks,
M

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dac6114e-b1cb-4b00-b313-8357eaf59ae7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment