Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range.all_products can return duplicates - ensure it doesn't #1942

Merged
merged 1 commit into from
Jan 11, 2016
Merged

Range.all_products can return duplicates - ensure it doesn't #1942

merged 1 commit into from
Jan 11, 2016

Conversation

solarissmoke
Copy link
Member

Range.all_products does a few OR joins on ManytoMany relationships. Because of the OUTER JOINs that are generated by this query, it is possible to end up with duplicates in the resulting queryset.

To reproduce, create a range which has only one product (which has been added using its SKU rather than by applying a category to the range). When the range is saved, the product will appear three (or four) times in the queryset returned by all_products.

This patch just adds a distinct() to the end of the query to ensure that this doesn't happen.

Range::all_products does a few OR joins on ManytoMany relationships. Because of the OUTER JOINs that are generated by this query, it is possible to end up with duplicates in the resulting queryset.

To reproduce, create a range which has only one product (which has been added using its SKU rather than by applying a category to the range). When the range is saved, the product will appear three (or four) times in the queryset returned by all_products.

This patch just adds a `distinct()` to the end of the query to ensure that this doesn't happen.
@solarissmoke solarissmoke changed the title Range::all_products can return duplicates - ensure it doesn't Range.all_products can return duplicates - ensure it doesn't Dec 15, 2015
@maiksprenger
Copy link
Member

That makes perfect sense. Thanks for testing and fixing this.

maiksprenger added a commit that referenced this pull request Jan 11, 2016
Range.all_products can return duplicates - ensure it doesn't
@maiksprenger maiksprenger merged commit e549d72 into django-oscar:master Jan 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants