[Django] #29522: Serializers are hard to modify

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #29522: Serializers are hard to modify

Django
#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.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/048.cc437fd1d95dd8fb34db0719382d33a4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29522: Serializers are hard to modify

Django
#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` 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.

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.

 * 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#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.35fd6eb0e41e01e3faef6fceaa247ee7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29522: Serializers are hard to modify

Django
In reply to this post by Django
#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
> 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.

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.

 * 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#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.ecfcc469bd708a1e2584a35e7930f69c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29522: Serializers are hard to modify

Django
In reply to this post by Django
#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
> 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.

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.

 * 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#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.4231efae7c89752669fcd52230eacee9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29522: Serializers are hard to modify

Django
In reply to this post by Django
#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.6db643e3021778850a02ec0270d7267b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29522: Make Serializers easier to modify (was: Serializers are hard to modify)

Django
In reply to this post by Django
#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.b1b9c116012a2562917feb04132b55cd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29522: Make Serializers easier to modify

Django
In reply to this post by Django
#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.471a5bf17c9ef1fa936c51feaee01bd1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.