[Django] #29747: Django 2.1.1 : UUID in loaddata fixture raise ValidationError on objects having OneToOne relationship (uuid as FK).

10 views
Skip to first unread message

Django

unread,
Sep 8, 2018, 3:43:35 PM9/8/18
to django-...@googlegroups.com
#29747: Django 2.1.1 : UUID in loaddata fixture raise ValidationError on objects
having OneToOne relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
stockersky |
Type: | Status: new
Uncategorized |
Component: Testing | Version: 2.1
framework | Keywords: uuid fixture
Severity: Normal | loaddata OneToOne
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hello,

I was working on my django project with version 2.0.
Today I redeployed my development environment and installed the lastest
Django version through pip : 2.1.1

While loading my database fixture to populate it (python manage.py
loaddata data_fixture.json), it raised :


{{{
Traceback (most recent call last):
File "/PROJECTS/SOFTWARES/pvenvs/cvdjango/lib/python3.6/site-
packages/django/db/models/fields/__init__.py", line 2325, in to_python
return uuid.UUID(value)
File "/PROJECTS/SOFTWARES/python366/lib/python3.6/uuid.py", line 140, in
__init__
raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadecimal UUID string

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/PROJECTS/SOFTWARES/pvenvs/cvdjango/lib/python3.6/site-
packages/django/core/serializers/python.py", line 100, in Deserializer
data[Model._meta.pk.attname] = Model._meta.pk.to_python(d.get('pk'))
File "/PROJECTS/SOFTWARES/pvenvs/cvdjango/lib/python3.6/site-
packages/django/db/models/fields/related.py", line 874, in to_python
return self.target_field.to_python(value)
File "/PROJECTS/SOFTWARES/pvenvs/cvdjango/lib/python3.6/site-
packages/django/db/models/fields/__init__.py", line 2330, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["La valeur «\xa020\xa0» n'est pas
un UUID valide."]

......................

raise base.DeserializationError.WithData(e, d['model'], d.get('pk'),
None)
django.core.serializers.base.DeserializationError: Problem installing
fixture
'/PROJECTS/CODE/cv_project/cv_frontend/fixtures/data_fixture.json': ["La
valeur «\xa020\xa0» n'est pas un UUID valide."]:
(cv_frontend.PersonalInfo:pk=20) field_value was 'None'

}}}

I flushed migrations, dropper/recreate database and ran migrations again.
Still has the error...

I could actually still create the object having uuid as PK in the admin
console and link other objects to it.


== Then I began to delete objects in my fixture file and try to run again
loaddata : when I deleted every fixture object that had OneToOne
relationship, it passed!!!

I finally rolled back to Django 2.0 and could run the whole fixture with
no problem!

Does it sound like a bug?

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

Django

unread,
Sep 8, 2018, 3:44:35 PM9/8/18
to django-...@googlegroups.com
#29747: Django 2.1.1 : UUID in loaddata fixture raise ValidationError on objects
having OneToOne relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: stockersky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.1
Severity: Normal | Resolution:
Keywords: uuid fixture | Triage Stage:
loaddata OneToOne | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* type: Uncategorized => Bug


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

Django

unread,
Sep 8, 2018, 4:01:59 PM9/8/18
to django-...@googlegroups.com
#29747: UUID in loaddata fixture raise ValidationError on objects having OneToOne

relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: stockersky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.1
Severity: Normal | Resolution:
Keywords: uuid fixture | Triage Stage:
loaddata OneToOne | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by stockersky:

Old description:

New description:

Hello,

......................

}}}

I flushed migrations, dropped/recreate database and ran migrations again.
Still had the error...

I could actually still create an object having uuid as PK in the admin


console and link other objects to it.


== Then I began to delete objects in my fixture file and try to run again
loaddata : when I deleted every fixture object that had OneToOne
relationship, it passed!!!

I finally rolled back to Django 2.0 and could run the whole fixture with
no problem!

Does it sound like a bug?

--

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

Django

unread,
Sep 8, 2018, 4:04:22 PM9/8/18
to django-...@googlegroups.com
#29747: Django 2.1.1 : UUID in loaddata fixture raise ValidationError on objects
having OneToOne relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: stockersky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.1
Severity: Normal | Resolution:
Keywords: uuid fixture | Triage Stage:
loaddata OneToOne | Unreviewed
Has patch: 0 | Needs documentation: 0

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

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

Django

unread,
Sep 8, 2018, 9:35:15 PM9/8/18
to django-...@googlegroups.com
#29747: Django 2.1.1 : UUID in loaddata fixture raise ValidationError on objects
having OneToOne relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: stockersky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.1
Severity: Normal | Resolution:
Keywords: uuid fixture | Triage Stage:
loaddata OneToOne | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Tim Graham):

Do you have the value `\xa020\xa0` in your fixtures? I'm not sure what
that's supposed to be but it doesn't look like a valid UUID as the error
message suggests.

--
Ticket URL: <https://code.djangoproject.com/ticket/29747#comment:4>

Django

unread,
Sep 9, 2018, 1:52:34 PM9/9/18
to django-...@googlegroups.com
#29747: Django 2.1.1 : UUID in loaddata fixture raise ValidationError on objects
having OneToOne relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: stockersky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.1
Severity: Normal | Resolution:
Keywords: uuid fixture | Triage Stage:
loaddata OneToOne | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by stockersky):

No, I don't have anything like this in my fixture. I use valid UUID's
Actually, as I tried to use another UUID in my fixture, I noticed the
value `\xa020\xa0` was always in the message.

--
Ticket URL: <https://code.djangoproject.com/ticket/29747#comment:5>

Django

unread,
Sep 9, 2018, 2:45:35 PM9/9/18
to django-...@googlegroups.com
#29747: Django 2.1.1 : UUID in loaddata fixture raise ValidationError on objects
having OneToOne relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: stockersky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.1
Severity: Normal | Resolution:
Keywords: uuid fixture | Triage Stage:
loaddata OneToOne | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Tim Graham):

Can you provide a sample project that reproduces the problem?

--
Ticket URL: <https://code.djangoproject.com/ticket/29747#comment:6>

Django

unread,
Sep 9, 2018, 3:00:39 PM9/9/18
to django-...@googlegroups.com
#29747: Django 2.1.1 : UUID in loaddata fixture raise ValidationError on objects
having OneToOne relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: stockersky | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 2.1
Severity: Normal | Resolution:
Keywords: uuid fixture | Triage Stage:
loaddata OneToOne | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by stockersky):

models :


{{{
import uuid
from django.db import models

class MyClass1(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
editable=False)
name = models.CharField(max_length=20)

class MyClass2(models.Model):
name = models.CharField(max_length=20)
myclass1 = models.OneToOneField(MyClass1, on_delete=models.CASCADE,
primary_key=True)
}}}

Fixture :


{{{
[
{
"model": "my_app.MyClass1",
"pk": "7bc3c004-05d6-4d4d-a70b-cf0507320784",
"fields": {
"name": "blabla"
}
},
{
"model": "my_app.MyClass2",
"pk": "20",
"fields": {
"name": "blibli",
"myclass1": "7bc3c004-05d6-4d4d-a70b-cf0507320784"
}
}
]
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29747#comment:7>

Django

unread,
Sep 9, 2018, 6:20:43 PM9/9/18
to django-...@googlegroups.com
#29747: UUID in loaddata fixture raise ValidationError on objects having OneToOne

relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: stockersky | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: uuid fixture | Triage Stage:
loaddata OneToOne | 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
* component: Testing framework => Database layer (models, ORM)
* resolution: => invalid


Comment:

Bisected to e50add6ca1605dcc06c8c5a5770342779a4d5124, however, it looks
like you have invalid fixture data. `"pk": "20",` should be a UUID since
you have `primary_key=True` on the `OneToOneField`, shouldn't it?

--
Ticket URL: <https://code.djangoproject.com/ticket/29747#comment:8>

Django

unread,
Sep 10, 2018, 2:57:05 PM9/10/18
to django-...@googlegroups.com
#29747: UUID in loaddata fixture raise ValidationError on objects having OneToOne

relationship (uuid as FK).
-------------------------------------+-------------------------------------
Reporter: stockersky | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: uuid fixture | Triage Stage:
loaddata OneToOne | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by stockersky):

Thanks for pointing out my mistake, Tim!
After fixing it, it works with Django 2.1.1.
Actually, maybe Django 2.0 was too permissive on the fixture because
despite my error, it never raised an exception...
Notwithstanding, it didn't create those wrong pk fields on the database
side.
My bad, I'm sorry for it.

--
Ticket URL: <https://code.djangoproject.com/ticket/29747#comment:9>

Reply all
Reply to author
Forward
0 new messages