Hi all,

We have a project that uses UUIDs as a primary key for some objects. Our 
project is deployed on AWS via Elastic Beanstalk. After the initial deploy, 
everything works fine, but at some point, we encounter the following error, 
deep within Django:

ValidationError: ["'7c6eee47-53d0-48f6-a8b7-8aff82bc47c3' is not a valid 
UUID."]

Now, that certainly is a valid UUID; just pass it as a parameter to 
uuid.UUID to verify that. So this is definitely odd. We use Sentry for our 
error logging, and I dove into the stack trace, which I'll post a picture 
of:

[image: stack_trace.png]


As can be seen in the stack trace, the following thing seems to happen:

1. Line 2315 is supposed to check for whether the value is already a UUID. 
That check fails (the purple line above indicates that the execution path 
has reached that line). Note that below, Sentry gives value as a UUID 
object.
2. Line 2316 is therefore invoked, calling self.to_python(value)

Here's the to_python function in its entirety (it can be found in 
django/db/models/fields/__init__.py):

2322:    def to_python(self, value):
2323:        if value is not None and not isinstance(value, uuid.UUID):
2324:            try:
2325:                return uuid.UUID(value)
2326:            except (AttributeError, ValueError):
2327:                raise exceptions.ValidationError(
2328:                    self.error_messages['invalid'],
2329:                    code='invalid',
2330:                    params={'value': value},
2331:                )
2332:        return value

3. The isinstance check at 2323 also fails, and so uuid.UUID(value) is 
invoked, which throws the ValidationError shown above, since the value 
passed into the constructor is not a string.

Now, the really, really weird thing about this problem is that *it goes 
away when we redeploy the code*. We then seem to operate normally for some 
time (as short as half a day, as long as several weeks) and then the 
problem crops up again. And on top of all of this, we can't seem to at all 
reproduce it locally; it only shows up in the production environment on AWS.

This is bedeviling our entire team and I would love to know if anyone has 
encountered a something like this or can provide any insight into just what 
is happening here. It seems that it should not be possible and yet it's 
happening.

-- 
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+unsubscr...@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/7f720fd9-8c4f-43a0-b084-e41f39d2305a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to