Fixed #28222 -- Allowed settable properties in QuerySet.update_or_create()/get_or_create() defaults.

This commit is contained in:
Alex 2017-05-19 06:40:43 -04:00 committed by Tim Graham
parent 385cf7091e
commit 37ab3c3f9d
5 changed files with 38 additions and 5 deletions

View file

@ -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(