[Django] #29293: valid UUID is not a valid UUID

53 views
Skip to first unread message

Django

unread,
Apr 6, 2018, 12:33:11 AM4/6/18
to django-...@googlegroups.com
#29293: valid UUID is not a valid UUID
-------------------------------------+-------------------------------------
Reporter: alfaro28 | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: 1.11
layer (models, ORM) | Keywords: UUIDField,
Severity: Normal | postgresql, uuid
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When using UUIDField with postgresql sometimes the field initialization
will fail, seems like postgresql sometimes returns some kind of UUID value
that fails the


{{{
isinstance(value, uuid.UUID)
}}}


validation and causes an exception, I don't really know how to reproduce,
because for a time it happened to me almost every day (randomly), but it's
been 7-8 months since the last time. I also want to clarify, once this
problem "starts", it will fail every single time until you restart the
server, after the restart everything works as it should (for a time
aparently). I'm pretty sure it's not django's fault but it should be
fairly easy to protect against this scenario. I think adding str() around
value should fix this, it would look like this:


{{{
def to_python(self, value):
if value is not None and not isinstance(value, uuid.UUID):
try:
return uuid.UUID(str(value))
except (AttributeError, ValueError):
raise exceptions.ValidationError(
self.error_messages['invalid'],
code='invalid',
params={'value': value},
)
return value
}}}

Since django already is using the "hex" parameter for the UUID constructor
and hex asumes a string, this makes sense to me

Link with aditional info:
[https://stackoverflow.com/questions/45990550/valid-uuid-is-not-a-valid-
uuid]

--
Ticket URL: <https://code.djangoproject.com/ticket/29293>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 6, 2018, 10:08:16 AM4/6/18
to django-...@googlegroups.com
#29293: valid UUID is not a valid UUID
-------------------------------------+-------------------------------------
Reporter: Jorge Alfaro | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: UUIDField, | Triage Stage:
postgresql, uuid | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

I don't think Django is at fault. From [https://groups.google.com/d/topic
/django-users/ZGb8ofw1Ux8/discussion django-users]:

> I think the problem comes from mod_wsgi. I had the same problem when
virtualhost listen on multiple ports.
> Please look at this GH issue
https://github.com/GrahamDumpleton/mod_wsgi/issues/206
> and try this by
https://github.com/GrahamDumpleton/mod_wsgi/issues/206#issuecomment-305019825
by Dumpleton.
>
> The real issue : isinstance(value, uuid.UUID) is failling because of the
use of sub interpreters.
> Details in the mod_wsgi documentation :
http://modwsgi.readthedocs.io/en/develop/user-guides/processes-and-
threading.html#python-sub-interpreters and
http://modwsgi.readthedocs.io/en/develop/configuration-
directives/WSGIApplicationGroup.html.

--
Ticket URL: <https://code.djangoproject.com/ticket/29293#comment:1>

Django

unread,
Apr 6, 2018, 1:19:11 PM4/6/18
to django-...@googlegroups.com
#29293: valid UUID is not a valid UUID
-------------------------------------+-------------------------------------
Reporter: Jorge Alfaro | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: UUIDField, | Triage Stage:
postgresql, uuid | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jorge Alfaro):

I completly understand it's not a django problem, but the links posted
don't really provide a solution just an explanation to the problem, and I
think django can "recover" from this issue easily with the solution I
provided, do you see any problem with the extra validation? (the str())

Replying to [comment:1 Tim Graham]:


> I don't think Django is at fault. From
[https://groups.google.com/d/topic/django-users/ZGb8ofw1Ux8/discussion
django-users]:
>
> > I think the problem comes from mod_wsgi. I had the same problem when
virtualhost listen on multiple ports.
> > Please look at this GH issue
https://github.com/GrahamDumpleton/mod_wsgi/issues/206
> > and try this by
https://github.com/GrahamDumpleton/mod_wsgi/issues/206#issuecomment-305019825
by Dumpleton.
> >
> > The real issue : isinstance(value, uuid.UUID) is failling because of
the use of sub interpreters.
> > Details in the mod_wsgi documentation :
http://modwsgi.readthedocs.io/en/develop/user-guides/processes-and-
threading.html#python-sub-interpreters and
http://modwsgi.readthedocs.io/en/develop/configuration-
directives/WSGIApplicationGroup.html.

--
Ticket URL: <https://code.djangoproject.com/ticket/29293#comment:2>

Django

unread,
Apr 6, 2018, 7:05:09 PM4/6/18
to django-...@googlegroups.com
#29293: valid UUID is not a valid UUID
-------------------------------------+-------------------------------------
Reporter: Jorge Alfaro | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: UUIDField, | Triage Stage:
postgresql, uuid | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

I don't think Django should make any effort to work around broken
configurations. If `isinstance(value, uuid.UUID)` doesn't work, other code
may also not work.

--
Ticket URL: <https://code.djangoproject.com/ticket/29293#comment:3>

Reply all
Reply to author
Forward
0 new messages