Open jhonatan-lopes opened 1 year ago
Hey @jhonatan-lopes, thanks for raising this. I spent some time debugging it and I found that it's related to how query trackers are pickled.
get_product_subset
returns the products after they've been pickled via cache.get_or_set
.
I recently implemented custom hooks to solve a similar issue: Fix pickling errors with related instances.
Currently, the __getstate__
method returns only values that were added to the tracker dictionary, not the one defined in the __slots__
attribute. That explains why we have the AttributeError: constructed
since constructed
is defined in the __slots__
.
I thought about adding all the values in __slots__
when pickling but that would introduce more serious bugs if everything else remains unchanged. Handling stateful objects is quite tricky with pickle
so I think we we'll need to think more about it.
When testing the view that raises errors, you can modify the last line from get_product_subset
to the following as a temporary workaround:
return cache.get_or_set(key, products, 24 * 60 * 60) # Set cache for 24h
# Change to
cache.get_or_set(key, products, 24 * 60 * 60) # Set cache for 24h
return products
Hi @Tijani-Dia, thanks for the quick investigation! Your proposed solution worked like a charm!
When trying to request a URL after installing the package, I get an
AttributeError
when trying to access a page:To reproduce:
dj_tracker
(adding either todev-requirements.in
orrequirements.in
)inv pip-compile-lock
inv setup
locally to setup the dev environment and create some fake data