mirror of
https://github.com/django/django.git
synced 2025-09-27 12:39:17 +00:00
Fixed #28222 -- Allowed settable properties in QuerySet.update_or_create()/get_or_create() defaults.
This commit is contained in:
parent
385cf7091e
commit
37ab3c3f9d
5 changed files with 38 additions and 5 deletions
|
@ -504,12 +504,14 @@ class QuerySet:
|
|||
lookup[f.name] = lookup.pop(f.attname)
|
||||
params = {k: v for k, v in kwargs.items() if LOOKUP_SEP not in k}
|
||||
params.update(defaults)
|
||||
property_names = self.model._meta._property_names
|
||||
invalid_params = []
|
||||
for param in params:
|
||||
try:
|
||||
self.model._meta.get_field(param)
|
||||
except exceptions.FieldDoesNotExist:
|
||||
if param != 'pk': # It's okay to use a model's pk property.
|
||||
# It's okay to use a model's property if it has a setter.
|
||||
if not (param in property_names and getattr(self.model, param).fset):
|
||||
invalid_params.append(param)
|
||||
if invalid_params:
|
||||
raise exceptions.FieldError(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue