In [1]: import uuid

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

BUT

In [3]: uuid.UUID4('61877565-5fe5-4175-9f2b-d24704df0b74')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-8d12e49c94ea> in <module>()
----> 1 uuid.UUID4('61877565-5fe5-4175-9f2b-d24704df0b74')

AttributeError: 'module' object has no attribute 'UUID4'


So uuid.UUID4() [or 3 or whatever] can only be used a certain way, as in
Michael's example?

The remaining question for me, then, is *what is the proper format *for a
uuid in a json fixture, or any other document I am trying to mass import
into Django?

61877565-5fe5-4175-9f2b-d24704df0b74 - (apparently not)

'61877565-5fe5-4175-9f2b-d24704df0b74'

('61877565-5fe5-4175-9f2b-d24704df0b74')

UUID('61877565-5fe5-4175-9f2b-d24704df0b74')

urn:uuid('61877565-5fe5-4175-9f2b-d24704df0b74')

some other variation I haven't come up with yet?

Here is a portion of my json document:

[{"model": "essell.Code", "fields": { "uuid":
"48189959-be4c-4f10-819a-f1657061b3cd", "arrow": "Amendment II",
"shorttitle": "", "popularname": "Keep & Bear Arms", "acronym": "",
"offcite": "", "brokenarrow": "", "slug": "amendment-ii-keep-bear-arms",
"codetext": "A well regulated Militia, being necessary to the security of a
free State, the right of the people to keep and bear Arms, shall not be
infringed.", "effdate": "1792-03-13", "sunsetdate": "", "sunsetcause":
"''", "postdate": "2016-02-05 13:06:53.20548-06", "crossref": "''",
"codekind": "Article", "codekindsortseq": "1", "codelevel": "Constitution",
"codelevelsortseq": "1", "siblingrank": "11", "childof_id": "",
"jurisdiction_id": "e6e11b06-ea3b-4e98-a31f-9a83447ad884"} }, {"model"
....

As you can see, the uuid is double quoted, but so are all the keys and
values. This is normal json format as I understand it. So should the uuid
be single quoted inside the double quotes? i.e.

"'61877565-5fe5-4175-9f2b-d24704df0b74'"

How do I get this done? Thanks.




On Thu, Feb 18, 2016 at 4:10 PM, James Schneider <jrschneide...@gmail.com>
wrote:

>
>
> On Thu, Feb 18, 2016 at 8:20 AM, Malik Rumi <malik.a.r...@gmail.com>
> wrote:
>
>> James,
>>
>> I used csvkit csvkit.readthedocs.org/en/latest/index.html to convert the
>> csv to json.
>>
>
> Looks legit. I'll just assume it creates syntactically correct JSON,
> otherwise it probably wouldn't last long as a public package.
>
>
>>
>> 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.
>>>
>>
>> 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.
>>
>
> Yes, that is a bit confusing, and admittedly fooled me as well. I only
> glanced at the tables of available formats and didn't look at the examples
> below. I should have known better since I did some other work with UUID's a
> short while ago in the same format and didn't run into an issue.
>
>
>>
>>
> 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
>>  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?!
>>
>
> I think you're misinterpreting what I was trying to say. Having a valid
> JSON syntax (ie the null sitting in the right spot next to the semi-colon)
> is a different issue than having incorrectly formatted data values within a
> valid JSON document using the right syntax (ie '8-4-4-4-12' vs
> 'urn:uuid:8-4-4-4-12'). I say incorrectly formatted to mean a value for an
> attribute that the parser responsible for interpreting the data is not
> expecting. It sounds like you ran into both issues.
>
> Basically, you need to grab the exact value from your JSON file and re-run
> the tests you have in your SO post, but be sure to add an 'import uuid'
> before running them, as Michal mentioned. Also, running
> uuid.UUID(8-4-4-4-12) without the quotes will never work, since Python
> thinks you are trying to pass it a variable with the name of your UUID,
> which is not a valid variable name, hence the reason you keep getting
> syntax errors, no matter what library or function calls you were trying to
> make.
>
> An example of your JSON that contains the UUID might also help.
>
> -James
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/Q4zybgExDyY/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CA%2Be%2BciXL%3DsE%3DAw7%2BON81RNo1G8cDmQ52Vy%3Dxg_YF1zkiFjQ9pw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXL%3DsE%3DAw7%2BON81RNo1G8cDmQ52Vy%3Dxg_YF1zkiFjQ9pw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAKd6oBz99MurnVZjCSrZO%3D8vv9qxCMEXjcpgwg-MzbH02dtrAw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to