[Django] #33427: Add new flag in loaddata command that loads fixture without overriding existing objects with same primary key

10 views
Skip to first unread message

Django

unread,
Jan 10, 2022, 11:04:39 AM1/10/22
to django-...@googlegroups.com
#33427: Add new flag in loaddata command that loads fixture without overriding
existing objects with same primary key
-------------------------------------+-------------------------------------
Reporter: Mohit | Owner: nobody
Solanki |
Type: New | Status: new
feature |
Component: Core | Version: dev
(Management commands) | Keywords: loaddata, fixture,
Severity: Normal | command
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Installing fixtures with django's `loaddata` command overrides objects
with the same primary key.
While this is not a problem if you are installing the fixtures against a
fresh DB with no data but in case you have
existing data then loading the fixture can be problematic as all the
existing rows with the same primary key will be updated
with the new data from the fixture(s)
It would be a good idea to have an additional flag that for e.g `--insert-
only` or something that tells django not to override existing objects with
the same primary key.

Note: I created this package https://github.com/mohi7solanki/dj-snake to
solve this issue but I think It would be a good idea to add this
functionality to `loaddata` itself

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

Django

unread,
Jan 10, 2022, 11:11:58 AM1/10/22
to django-...@googlegroups.com
#33427: Add new flag in loaddata command that loads fixture without overriding
existing objects with same primary key
-------------------------------------+-------------------------------------
Reporter: Mohit Solanki | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: loaddata, fixture, | Triage Stage:
command | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Old description:

> Installing fixtures with django's `loaddata` command overrides objects
> with the same primary key.
> While this is not a problem if you are installing the fixtures against a
> fresh DB with no data but in case you have
> existing data then loading the fixture can be problematic as all the
> existing rows with the same primary key will be updated
> with the new data from the fixture(s)
> It would be a good idea to have an additional flag that for e.g

> `--insert-only` or something that tells django not to override existing


> objects with the same primary key.
>
> Note: I created this package https://github.com/mohi7solanki/dj-snake to
> solve this issue but I think It would be a good idea to add this
> functionality to `loaddata` itself

New description:

Installing fixtures with django's `loaddata` command overrides objects
with the same primary key.
While this is not a problem if you are installing the fixtures against a
fresh DB with no data but in case you have
existing data then loading the fixture can be problematic as all the
existing rows with the same primary key will be updated
with the new data from the fixture(s)

It would be a good idea to have an additional flag like for e.g `--insert-


only` or something that tells django not to override existing objects with
the same primary key.

Note: I created this package https://github.com/mohi7solanki/dj-snake to
solve this issue but I think It would be a good idea to add this
functionality to `loaddata` itself

--

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

Django

unread,
Jan 10, 2022, 12:24:13 PM1/10/22
to django-...@googlegroups.com
#33427: Add new flag in loaddata command that loads fixture without overriding
existing objects with same primary key
-------------------------------------+-------------------------------------
Reporter: Mohit Solanki | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: loaddata, fixture, | Triage Stage:
command | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Adam Johnson):

Thanks for submitting the ticket Mohit. I'll let someone else (probably a
fellow) comment if it's worth accepting.

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

Django

unread,
Jan 11, 2022, 3:49:32 AM1/11/22
to django-...@googlegroups.com
#33427: Add new flag in loaddata command that loads fixture without overriding
existing objects with same primary key
-------------------------------------+-------------------------------------
Reporter: Mohit Solanki | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: loaddata, fixture, | Triage Stage:
command | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Carlton Gibson):

Hi Mohit.

I'm going to say wontfix here initially: I'm not sure there's much benefit
in complicating `loaddata`; the thought is to create your own command if
you need this, which is just what you've done — nice working sharing that.

It may be that a post to the DevelopersMailingList or
[https://forum.djangoproject.com Forum] would show more demand in which
case we could re-open…
Thanks.

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

Django

unread,
Jan 11, 2022, 3:49:41 AM1/11/22
to django-...@googlegroups.com
#33427: Add new flag in loaddata command that loads fixture without overriding
existing objects with same primary key
-------------------------------------+-------------------------------------
Reporter: Mohit Solanki | Owner: nobody
Type: New feature | Status: closed

Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution: wontfix

Keywords: loaddata, fixture, | Triage Stage:
command | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* status: new => closed
* resolution: => wontfix


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

Reply all
Reply to author
Forward
0 new messages