diff options
| author | Adam Johnson <me@adamj.eu> | 2025-09-05 11:04:27 +0100 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-10-16 14:52:22 -0400 |
| commit | a321d961b03d47b7f0c2e21a2370fc9e74c1889b (patch) | |
| tree | b57a131d63215b60f0c6fbfd8cb5f3e35fcff6e9 /django/db/models/fetch_modes.py | |
| parent | e097e8a12f21a4e92594830f1ad1942b31916d0f (diff) | |
Refs #28586 -- Made fetch modes pickle as singletons.
This change ensures that we don’t create new instances of fetch modes
when pickling and unpickling, saving memory and preserving their singleton
nature.
Diffstat (limited to 'django/db/models/fetch_modes.py')
| -rw-r--r-- | django/db/models/fetch_modes.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/django/db/models/fetch_modes.py b/django/db/models/fetch_modes.py index a22ccd8a23..2b5e6aa212 100644 --- a/django/db/models/fetch_modes.py +++ b/django/db/models/fetch_modes.py @@ -16,6 +16,9 @@ class FetchOne(FetchMode): def fetch(self, fetcher, instance): fetcher.fetch_one(instance) + def __reduce__(self): + return "FETCH_ONE" + FETCH_ONE = FetchOne() @@ -36,6 +39,9 @@ class FetchPeers(FetchMode): else: fetcher.fetch_one(instance) + def __reduce__(self): + return "FETCH_PEERS" + FETCH_PEERS = FetchPeers() @@ -48,5 +54,8 @@ class Raise(FetchMode): field_name = fetcher.field.name raise FieldFetchBlocked(f"Fetching of {klass}.{field_name} blocked.") from None + def __reduce__(self): + return "RAISE" + RAISE = Raise() |
