if we examine the following code:
class SomeModel(models.Model):
...
def save(self, *args, **kwargs):
self.validate_unique()
super().save()
def validate_unique(self, *args, **kwargs):
super().validate_unique(*args, **kwargs)
# Doing an ORM query on the model with *filter* on the model attributes & an associated model,
# and if exist - dont create a new instance, if not - create a new instance.
is_duplicated = SomeModel.objects.filter(name=given_name_from_user, attribute_from_associated_model=some_attr)
if is_duplicated:
raise Exception("go wrong")
# Else - continue to save
Now, it will work with the development server, but not with a production one like gunicorn or uvicorn, because the save method gurantee us atomicity, but not isolation, right?
for us to gurantee isolation, we should use ‘get_or_create’ on the view level?
I’m mistake somewhere?
Any comment will help, Thanks!