You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. Model.objects.update_or_create(key_field=key_value, defaults={}) is not routed automatically, when value existed. The reason is in it's realization:
defupdate_or_create(self, defaults=None, **kwargs):
""" Looks up an object with the given kwargs, updating one with defaults if it exists, otherwise creates a new one. Returns a tuple (object, created), where created is a boolean specifying whether an object was created. """defaults=defaultsor {}
lookup, params=self._extract_model_params(defaults, **kwargs)
self._for_write=Truetry:
obj=self.get(**lookup)
exceptself.model.DoesNotExist:
obj, created=self._create_object_from_params(lookup, params)
ifcreated:
returnobj, createdfork, vinsix.iteritems(defaults):
setattr(obj, k, v)
obj.save(using=self.db)
returnobj, False
obj has been got correctly, but self.db returns 'default'. As a result obj.save(using=self.db) fails.
The text was updated successfully, but these errors were encountered:
I can take a look. To be honest, I haven't done too much work on the routing myself but I know how it works. I know there are some flaws with Django around self.db state as it is a single field that can only track where something is rather than where it will be and will sometimes throw away the using arg.
Hi.
Model.objects.update_or_create(key_field=key_value, defaults={})
is not routed automatically, when value existed. The reason is in it's realization:obj has been got correctly, but
self.db
returns 'default'. As a resultobj.save(using=self.db)
fails.The text was updated successfully, but these errors were encountered: