mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #27118 -- Made QuerySet.get_or_create()/update_or_create() error for a non-field in their arguments.
This commit is contained in:
parent
b3330f52a8
commit
a5e13a0b92
3 changed files with 47 additions and 1 deletions
|
@ -527,6 +527,18 @@ class QuerySet(object):
|
|||
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)
|
||||
invalid_params = []
|
||||
for param in params:
|
||||
try:
|
||||
self.model._meta.get_field(param)
|
||||
except exceptions.FieldDoesNotExist:
|
||||
invalid_params.append(param)
|
||||
if invalid_params:
|
||||
raise exceptions.FieldError(
|
||||
"Invalid field name(s) for model %s: '%s'." % (
|
||||
self.model._meta.object_name,
|
||||
"', '".join(sorted(invalid_params)),
|
||||
))
|
||||
return lookup, params
|
||||
|
||||
def _earliest_or_latest(self, field_name=None, direction="-"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue