Opened 12 years ago

Closed 12 years ago

#19635 closed Cleanup/optimization (fixed)

Allow fields to be pickled

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Model field instances are not pickleable currently because the field's model isn't necessarily available (autocreated m2m models for example). This causes some ugly code in django.db.models.sql.query.Query __getstate__ and __setstate__ methods as we need to avoid pickling the fields found from the various structs in the Query.

To avoid this problem we can use __reduce__ to make fields pickleable. The idea is that we save the field's identifier (app_lable, model_name, field_name) in pickling, then use app cache to load the model, and then the field from the model in unpickling. This makes the Query code much nicer, and allows for extended use of fields in the Query structures.

Patch available from https://github.com/akaariai/django/tree/field_pickle

Change History (2)

comment:1 by Anssi Kääriäinen, 12 years ago

Another one that will get committed if nobody objects.

comment:2 by Anssi Kääriäinen <akaariai@…>, 12 years ago

Resolution: fixed
Status: newclosed

In f403653cf146384946e5c879ad2a351768ebc226:

Fixed #19635 -- Made fields pickleable

Note: See TracTickets for help on using tickets.
Back to Top