[Django] #34907: OperationalError during loaddata of fixtures with natural keys on multi-db

1 view
Skip to first unread message

Django

unread,
Oct 19, 2023, 7:44:53 AM10/19/23
to django-...@googlegroups.com
#34907: OperationalError during loaddata of fixtures with natural keys on multi-db
-------------------------------------+-------------------------------------
Reporter: fvkluck | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 4.2
layer (models, ORM) | Keywords: natural key, multi-
Severity: Normal | db, loaddata
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi all,

I'm running into a bug when trying to use fixtures with natural keys and
using multiple databases.

If I have two tables A and B, that are routed by a database router to db1
and db2 respectively, then I can load 'regular' fixtures of A in db2.
Django will correctly recognize that A data does not need to be loaded
into db2, and hence give the (correct) output that 0 objects are loaded
from 1 fixture.
However, if I keep everything the same, except that I use natural keys for
the data, then loaddata will give an OperationalError exception.

I've created a minimal reproduction here:
https://github.com/fvkluck/improved-dollop

In its readme I've put the reproduction, the full stacktrace, and explain
where I got my data. Shortest version of the repro is:
1. git clone https://github.com/fvkluck/improved-dollop
2. cd improved-dollop/repro
3. python manage.py migrate
4. python manage.py migrate --database=secondary
5. python manage.py loaddata someprimarymodel_natural.json
--database=secondary

This leads to an exception (OperationalError). Expected is: '0 objects
were loaded from 1 fixture'

Best,
Florian

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

Django

unread,
Oct 19, 2023, 9:07:01 AM10/19/23
to django-...@googlegroups.com
#34907: OperationalError during loaddata of fixtures with natural keys on multi-db
-------------------------------------+-------------------------------------
Reporter: Florian | Owner:
| abidkhan484
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: natural key, multi- | Triage Stage:
db, loaddata | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* owner: nobody => abidkhan484
* status: new => assigned


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

Reply all
Reply to author
Forward
0 new messages