[Django] #26237: uuid.UUID() generates 'invalid syntax' and 'badly formed' uuids

10 views
Skip to first unread message

Django

unread,
Feb 18, 2016, 12:51:18 PM2/18/16
to django-...@googlegroups.com
#26237: uuid.UUID() generates 'invalid syntax' and 'badly formed' uuids
-------------------------------+--------------------
Reporter: MalikRumi | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords: uuid
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Background: I've been struggling for about a week trying to use fixtures
to load initial data into a website. See
http://stackoverflow.com/questions/35463713/badly-formed-hexadecimal-uuid-
string-error-in-django-fixture-json-uuid-conversi and
https://groups.google.com/forum/#!topic/django-users/Q4zybgExDyY.

Once I did the test suggested to me on SO, it became clear that this was
not a json issue. That test was as follows:

In [5]: e.uuid
Out[5]: UUID('61877565-5fe5-4175-9f2b-d24704df0b74')
In [6]: uuid.UUID(61877565-5fe5-4175-9f2b-d24704df0b74)
File "<ipython-input-6-56137f5f4eb6>", line 1
uuid.UUID(61877565-5fe5-4175-9f2b-d24704df0b74)
^
SyntaxError: invalid syntax # It doesn't show here for some
reason, but the caret is pointing to the 4th '5' in the 12th position,
from left to right.

It did not matter if I copy pasted the uuid or retyped the whole thing by
hand, I got the same error. If I quoted the uuid, I got a different error:

In [7]: uuid.UUID('61877565-5fe5-4175-9f2b-d24704df0b74')
---------------------------------------------------------------------------
NameError Traceback (most recent call
last)
<ipython-input-7-3b4d3e5bd156> in <module>()
----> 1 uuid.UUID('61877565-5fe5-4175-9f2b-d24704df0b74')

NameError: name 'uuid' is not defined

I am using Ubuntu 15.10, Django 1.9.1, Postgresql 9.4 and Python 2.7.10. I
don't know if this a Python issue rather than a Django issue, but it
can't, or shouldn't, be that Django/Python can't accept, recognize, or
evaluate a uuid it generated seconds earlier.

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

Django

unread,
Feb 18, 2016, 3:04:13 PM2/18/16
to django-...@googlegroups.com
#26237: uuid.UUID() generates 'invalid syntax' and 'badly formed' uuids
-------------------------------+--------------------------------------
Reporter: MalikRumi | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution: invalid

Keywords: uuid | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by charettes):

* status: new => closed
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* resolution: => invalid


Old description:

New description:

--

Comment:

Hi MalikRumi,

I'm afraid this has nothing to do with Django.

From what I can see the first exception occurred because you forgot to
quote the string you attempted to pass to the `uuid.UUID` constructor.
You can get a similar exception by simply pasting the expression
`61877565-5fe5-4175-9f2b-d24704df0b74` in a Python shell.

The second exception occurred because you attempted to construct a
`uuid.UUID` instance by referring to the `uuid` module which you has not
imported in your shell global context. I guess you simply imported `UUID`
from `uuid` (you did `from uuid import UUID` instead of `import uuid`).

I suppose you got confused because the representation of `uuid.UUID`
objects (`repr(uuid.UUID('61877565-5fe5-4175-9f2b-d24704df0b74'))`), which
is what your shell is displaying by default in `Out[N]:`, always include
the `uuid` module prefix.

In the future please stick to the support channel (like the thread on
django-users@) until you get a confirmation this is actually a bug as this
tracker is not meant to be used as a support platform.

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

Django

unread,
Feb 19, 2016, 10:32:09 AM2/19/16
to django-...@googlegroups.com
#26237: uuid.UUID() generates 'invalid syntax' and 'badly formed' uuids
-------------------------------+--------------------------------------
Reporter: MalikRumi | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution: invalid

Keywords: uuid | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by MalikRumi):

1. Thank you for the explanation. I did as you suggested and got the
result you predicted:

In [1]: import uuid

In [2]: uuid.UUID('61877565-5fe5-4175-9f2b-d24704df0b74')
Out[2]: UUID('61877565-5fe5-4175-9f2b-d24704df0b74')

2. As I said in my original report, I had posted to the forums before
coming to you. One answer strongly suggested an issue, which is why I
decided to come to you. However, this morning I see a retraction/further
explanation from him that is more in line with what you said here. So I am
sorry for taking your time, but I thought I had run out of options.

3. What does 'confirmation' of a bug look like?

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

Django

unread,
Feb 19, 2016, 11:56:23 AM2/19/16
to django-...@googlegroups.com
#26237: uuid.UUID() generates 'invalid syntax' and 'badly formed' uuids
-------------------------------+--------------------------------------
Reporter: MalikRumi | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.9
Severity: Normal | Resolution: invalid

Keywords: uuid | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by charettes):

> What does 'confirmation' of a bug look like?

An exception with a traceback involving Django's source code should be a
good hint it might be Django bug.

In the case of your report Django isn't involved at all and both traceback
point to the cause of your errors (a syntax and name a error).

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

Reply all
Reply to author
Forward
0 new messages