Skip to content

Commit

Permalink
Improve multi db support (#335)
Browse files Browse the repository at this point in the history
Use the same database as the passed-in manager
  • Loading branch information
specialunderwear authored Feb 22, 2024
1 parent 20ba73b commit 8ea9bf5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion oscarapi/serializers/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ def update(self, instance, validated_data):
# child product.
product.attr._dirty.clear() # pylint: disable=protected-access
product.attr.save()
return list(product.attribute_values.filter(attribute__code__in=attr_codes))
# we have to make sure to use the correct db_manager in a multidatabase
# context, we make sure to use the same database as the passed in manager
local_attribute_values = product.attribute_values.db_manager(
instance.db
).filter(attribute__code__in=attr_codes)
return list(local_attribute_values)


class ProductAttributeValueSerializer(OscarModelSerializer):
Expand Down

0 comments on commit 8ea9bf5

Please sign in to comment.