1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #31486 -- Deprecated passing unsaved objects to related filters.

Co-Authored-By: Hasan Ramezani <hasan.r67@gmail.com>
This commit is contained in:
Albert Defler
2022-02-05 20:00:20 +00:00
committed by Mariusz Felisiak
parent 11cc227344
commit 2b6a3baebe
4 changed files with 46 additions and 1 deletions

View File

@@ -1,3 +1,5 @@
import warnings
from django.db.models.lookups import (
Exact,
GreaterThan,
@@ -7,6 +9,7 @@ from django.db.models.lookups import (
LessThan,
LessThanOrEqual,
)
from django.utils.deprecation import RemovedInDjango50Warning
class MultiColSource:
@@ -40,6 +43,15 @@ def get_normalized_value(value, lhs):
from django.db.models import Model
if isinstance(value, Model):
if value.pk is None:
# When the deprecation ends, replace with:
# raise ValueError(
# "Model instances passed to related filters must be saved."
# )
warnings.warn(
"Passing unsaved model instances to related filters is deprecated.",
RemovedInDjango50Warning,
)
value_list = []
sources = lhs.output_field.path_infos[-1].target_fields
for source in sources: