Open merpius opened 1 month ago
It seems like just checking obj for the
QUERYING_PROPERTIES_MARKER
attribute before callingdelattr
would get past this, but is this maybe a sign of another issue?
It is. The marker should always be present - if it is not, other required parts of the code did not run (meaning something else went wrong), which is why the delattr
call is performed like that.
I don't see anything wrong with the model you've posted, so I'm guessing there's a bug here. Although I'm somewhat confused as there are definitely queryset deletions in django-queryable-properties' test setup. What caught my eye is this part of the stack trace:
File "/var/lib/jenkins/envs/ss-test-p3/lib/python3.8/site-packages/django/db/models/deletion.py", line 223, in collect
elif sub_objs:
This means that there are other objects being deleted along with the Tenant
objects by cascading. Could you check which other objects are being deleted and whether their models also contain queryable properties? This could at least give me a hint about what the actual issue is.
Could you also state your Django version and django-queryable-properties version? With this information, I could try to recreate this scenario on my end.
Django==2.2.28 django-queryable-properties==1.9.3
This model is the only one using queryable properties, though there are many that have a foreign key to the Tenant model (I think most have the cascade on_delete setting). Could the parent
field be the culprit here? It is referencing back to the same model (which is, of course, a queryable property model...).
So far I've been unable to recreate the issue. Using Django 2.2, I tried to delete (via cascading from a model with queryable properties):
self
-FKsAll of them worked without encountering any problems.
I've also noticed that Django uses the base manager of each related model to query instances that should be deleted by cascading. If you set the queryable properties manager as shown above (objects = QueryablePropertiesManager()
), this should only affect the default manager (attribute _default_manager
), but not the base manager (attribute _base_manager
) of that model. The base manager should still be one of Django's basic manager instances - which also means that there shouldn't be any queryable property code involved while deleting objects by cascading at all. This is why I'm starting to suspect that there's something else happening with the managers in your particular project.
Since I can't recreate and investigate the issue, you could:
elif sub_objs:
parts of the stack trace and inspect the sub_objs
queryset that leads to the error (What model is the queryset for? What is that model's _base_manager
? Etc.)
I have a model class with the following setup;
There's never a parent of a parent, thus the comment implying that. (Not sure if that is relevant to this issue). Parent is always either None or another Tenant.
In the teardown for unit tests I'm getting this;
Am I doing something wrong here in the setup? Am I missing something? Or is this a bug? It seems like just checking
obj
for theQUERYING_PROPERTIES_MARKER
attribute before callingdelattr
would get past this, but is this maybe a sign of another issue?