[Django] #29522: Serializers are hard to modify

38 views
Skip to first unread message

Django

unread,
Jun 24, 2018, 10:19:29 PM6/24/18
to django-...@googlegroups.com
#29522: Serializers are hard to modify
------------------------------------------------+------------------------
Reporter: Levi Cameron | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Serialization) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
**Use case**

Three times now I've had need to modify the ORM serializers for project
use. In every case I've had to replicate large parts (if not all) of
`django.core.serializers.base` in order to change 1 or 2 lines because
certain calls to functions in `django.core.serializers.base` form the
serializers are hardcoded.

* Changing JSON serialization to output in alphabetical order (so that
`dumpdata` doesn't reorder every field each time you run it)
* Changing deserialization to use `_base_manager` instead of
`_default_manager` (due to extra constraints on a custom manager)
* Implementing fixes for #7202, #7350 before they were merged

**Proposal**
I propose that instead of calling the following functions directly, the
serializer classes are modified to call an instance method of the same
name that then calls the existing module-level functions. This would allow
the ability to more easily override just one aspect of serializer
functionality without having to replicate large swathes of code.

I am not proposing to move these functions into the python serializer
class directly because this may break compatibility with existing code
that depends on the existing functions.

* `django.core.serializers.base.build_instance`
* `django.core.serializers.base.deserializer_m2m_values`
* `django.core.serializers.base.deserializer_fk_values`
* `django.core.serializers.python._get_model` (given that this is already
an internal function, implementation can be pushed into the class
directly)

(It might also be nice if the `json` and `pyyaml` classes could also have
`PythonDeserializer` be made a class attribute but that would involve
turning the `Deserializer` function into a class and is not nearly as much
code to override these as the functions above)


If this sounds acceptable, I will submit a patch.

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

Django

unread,
Jun 24, 2018, 10:20:57 PM6/24/18
to django-...@googlegroups.com
#29522: Serializers are hard to modify
-------------------------------------+-------------------------------------

Reporter: Levi Cameron | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Levi Cameron:

Old description:

New description:

**Use case**

Three times now I've had need to modify the ORM serializers for project
use. In every case I've had to replicate large parts (if not all) of
`django.core.serializers.base` in order to change 1 or 2 lines because

certain calls to functions in `django.core.serializers.base` from the
serializers are hardcoded.

--

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

Django

unread,
Jun 24, 2018, 10:26:57 PM6/24/18
to django-...@googlegroups.com
#29522: Serializers are hard to modify
-------------------------------------+-------------------------------------

Reporter: Levi Cameron | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Levi Cameron:

Old description:

> **Use case**


>
> Three times now I've had need to modify the ORM serializers for project
> use. In every case I've had to replicate large parts (if not all) of
> `django.core.serializers.base` in order to change 1 or 2 lines because

> certain calls to functions in `django.core.serializers.base` from the

New description:

**Use case**

Three times now I've had need to modify the ORM serializers for project

use. In some cases I've had to replicate large parts (if not most) of


`django.core.serializers.base` in order to change 1 or 2 lines because

certain calls to functions in `django.core.serializers.base` from the
serializers are hardcoded.

--

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

Django

unread,
Jun 24, 2018, 10:27:49 PM6/24/18
to django-...@googlegroups.com
#29522: Serializers are hard to modify
-------------------------------------+-------------------------------------

Reporter: Levi Cameron | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Levi Cameron:

Old description:

> **Use case**


>
> Three times now I've had need to modify the ORM serializers for project

> use. In some cases I've had to replicate large parts (if not most) of


> `django.core.serializers.base` in order to change 1 or 2 lines because

> certain calls to functions in `django.core.serializers.base` from the

New description:

**Use case**

Three times now I've had need to modify the ORM serializers for project

use. In some cases I've had to replicate large parts (if not most) of
`django.core.serializers.python` in order to change 1 or 2 lines because
certain calls to functions in `django.core.serializers.base` from the
serializers are hardcoded.

--

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

Django

unread,
Jul 11, 2018, 3:12:40 AM7/11/18
to django-...@googlegroups.com
#29522: Serializers are hard to modify
--------------------------------------+------------------------------------

Reporter: Levi Cameron | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Serialization) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

* stage: Unreviewed => Accepted


Comment:

This sounds reasonable to me. My main thought would be to make sure the
new hooks a properly documented etc. But yes, good idea.

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

Django

unread,
Jul 11, 2018, 3:13:12 AM7/11/18
to django-...@googlegroups.com
#29522: Make Serializers easier to modify
--------------------------------------+------------------------------------

Reporter: Levi Cameron | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Serialization) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
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/29522#comment:5>

Django

unread,
Jul 15, 2018, 7:37:19 AM7/15/18
to django-...@googlegroups.com
#29522: Make Serializers easier to modify
--------------------------------------+------------------------------------
Reporter: Levi Cameron | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Serialization) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Herbert Fortes):

* cc: Herbert Fortes (added)


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

Django

unread,
Apr 13, 2019, 4:52:30 AM4/13/19
to django-...@googlegroups.com
#29522: Make Serializers easier to modify
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Emad
Type: | Mokhtar
Cleanup/optimization | Status: assigned

Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Emad Mokhtar):

* owner: nobody => Emad Mokhtar
* status: new => assigned


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

Django

unread,
Apr 13, 2019, 8:26:27 AM4/13/19
to django-...@googlegroups.com
#29522: Make Serializers easier to modify
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Emad
Type: | Mokhtar
Cleanup/optimization | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ian Foote):

* cc: Ian Foote (added)


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

Django

unread,
Apr 13, 2019, 10:20:27 AM4/13/19
to django-...@googlegroups.com
#29522: Make Serializers easier to modify
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Emad
Type: | Mokhtar
Cleanup/optimization | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Emad Mokhtar):

[PR created](https://github.com/EmadMokhtar/django/tree/ticket_29522)

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

Django

unread,
Apr 14, 2019, 7:04:49 AM4/14/19
to django-...@googlegroups.com
#29522: Make Serializers easier to modify
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Emad
Type: | Mokhtar
Cleanup/optimization | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:10>

Django

unread,
Apr 19, 2019, 7:20:07 AM4/19/19
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.

-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Emad
Type: | Mokhtar
Cleanup/optimization | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:11>

Django

unread,
Mar 8, 2024, 3:06:04 AM3/8/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
--------------------------------------+------------------------------------
Reporter: Levi Cameron | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Core (Serialization) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: Emad Mokhtar => (none)
* status: assigned => new

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:12>

Django

unread,
Mar 18, 2024, 2:47:13 AM3/18/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
--------------------------------------+------------------------------------
Reporter: Levi Cameron | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Core (Serialization) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Ülgen Sarıkavak):

* cc: Ülgen Sarıkavak (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:13>

Django

unread,
Jul 2, 2024, 6:28:39 PM7/2/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Amir Karimi):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
* owner: (none) => Amir Karimi
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:14>

Django

unread,
Aug 14, 2024, 7:27:01 AM8/14/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:15>

Django

unread,
Sep 7, 2024, 9:06:06 AM9/7/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Amir Karimi):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:16>

Django

unread,
Sep 9, 2024, 6:01:38 AM9/9/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:17>

Django

unread,
Sep 9, 2024, 12:10:29 PM9/9/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Amir Karimi):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:18>

Django

unread,
Sep 10, 2024, 4:47:32 AM9/10/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:19>

Django

unread,
Sep 11, 2024, 1:14:57 PM9/11/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Amir Karimi):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:20>

Django

unread,
Sep 12, 2024, 7:44:36 AM9/12/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"b2501759eb91edddaeb5ddfccb40a44f39da7798" b250175]:
{{{#!CommitTicketReference repository=""
revision="b2501759eb91edddaeb5ddfccb40a44f39da7798"
Refs #29522 -- Improved test coverage of deserializers.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:21>

Django

unread,
Sep 13, 2024, 10:56:32 AM9/13/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:22>

Django

unread,
Sep 14, 2024, 2:12:46 PM9/14/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Amir Karimi):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:23>

Django

unread,
Sep 17, 2024, 4:42:09 AM9/17/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:24>

Django

unread,
Sep 17, 2024, 5:01:00 AM9/17/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: closed
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"ee5147cfd7de2add74a285537a8968ec074e70cd" ee5147cf]:
{{{#!CommitTicketReference repository=""
revision="ee5147cfd7de2add74a285537a8968ec074e70cd"
Fixed #29522 -- Refactored the Deserializer functions to classes.

Co-authored-by: Emad Mokhtar <emad.m...@veneficus.nl>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:25>

Django

unread,
Sep 19, 2024, 2:51:40 AM9/19/24
to django-...@googlegroups.com
#29522: Make Serializers easier to modify.
-------------------------------------+-------------------------------------
Reporter: Levi Cameron | Owner: Amir
Type: | Karimi
Cleanup/optimization | Status: closed
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"1fa84936408b84a6530d56cc1efed83ce6e7160c" 1fa84936]:
{{{#!CommitTicketReference repository=""
revision="1fa84936408b84a6530d56cc1efed83ce6e7160c"
Refs #29522 -- Fixed serializers/fixtures test crash if PyYAML isn't
installed.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29522#comment:26>
Reply all
Reply to author
Forward
0 new messages