On Thu, Feb 18, 2016 at 08:20:57AM -0800, Malik Rumi wrote:
> James,
> 
> I used csvkit csvkit.readthedocs.org/en/latest/index.html to convert the 
> csv to json.
> 
> On Wednesday, February 17, 2016 at 7:05:59 PM UTC-6, James Schneider wrote:
> >
> >
> >> The uuid.UUID() function is somewhat forgiving when it comes to providing 
> > values. See https://docs.python.org/3.5/library/uuid.html. Does the UUID 
> > in your JSON data match any of those formats? The only common format for a 
> > UUID that I've seen that doesn't match any of those formats would be 
> > 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' which is a string that contains 
> > dashes, but no surrounding braces. I believe that's the format that is 
> > pulled when using UUID's from Django installations by default. I'm actually 
> > surprised the Python UUID library doesn't support it, but maybe it's one of 
> > those RFC things that specifies the formats that must be accepted.
> >

This is not actually true, the Python uuid library accepts the
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' format without any complaints:

In [1]: import uuid

In [2]: x = uuid.uuid4()

In [3]: print(str(x))
f3ee7d49-42c9-4112-9533-66d62c87759d

In [4]: uuid.UUID('f3ee7d49-42c9-4112-9533-66d62c87759d')
Out[4]: UUID('f3ee7d49-42c9-4112-9533-66d62c87759d')

> Okay, THIS really bothers me for a couple of reasons. 1) Yes, my uuids are 
> in the 8-4-4-4-12 format. 2) Yes, this comes from using the uuidfield as 
> recommended in the 
> docs https://docs.djangoproject.com/es/1.9/ref/models/fields/#uuidfield 3) 
> You're right, this 8-4-4-4-12 format IS NOT on the Python docs page you 
> referred me to. 

While the 8-4-4-4-12 format without braces is not explicitly mentioned
in the list of examples on in the docs of uuid, it is in fact
supported; see the copy-paste from an ipython shell above.

Are you absolutely certain that your JSON file contains keys like the
following?

    {
        "my_uuid": "f3ee7d49-42c9-4112-9533-66d62c87759d"
    }

Could you show us an example JSON file that is giving you errors?

> How can Django say this is based on the Python uuid module when it does not 
> comply? What GOOD is it if it does not comply? Now maybe there is some 
> internal workings that hack a valid Python format. My guess is UUID(
> 'urn:uuid:12345678-1234-5678-1234-567812345678'). It wouldn't be that hard 
> to strip off the urn:uuid, and I know for a fact, because I've seen it with 
> my own eyes, there is code to strip out the dashes. But essentially you are 
> saying that my problems are NOT JSON (which I had started to suspect 
> anyway, see 
> http://stackoverflow.com/questions/35463713/badly-formed-hexadecimal-uuid-string-error-in-django-fixture-json-uuid-conversi
>  

In that SO question, most code snippets are not valid Python code,
because they do not have quotes around strings, which is why Python
tries to treat them as expressions (int literals, or variable names
with the minus operator in between). The last two samples with
NameError: name 'uuid' is not defined simply mean that you had not
imported uuid before executing those lines of code.

Regards,

Michal

>  2nd Update. But you also seem to be saying this is not a bug, but a 
> 'feature', because Django knows their uuid format does not comply. But that 
> doesn't make sense to me. How is it to be effectively used without 
> universal Python compliance? Why isn't this lack of compliance documented? 
> What is the workaround, or does it just mean junk the Django uuid 
> altogether as not ready for prime time and save yourself days and days of 
> work, like the days I wasted all last week on this thing?!

-- 
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/20160218171039.GE880%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: Digital signature

Reply via email to