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

Fix discarded duplicated products bug #4189

Merged
merged 1 commit into from Jun 8, 2022

Conversation

Azeem838
Copy link
Contributor

@Azeem838 Azeem838 commented Oct 4, 2021

Description
When a product is cloned and then discarded without changing the cloned variants SKU, if the product is ever cloned again then the cloning process will fail with a variant and master variant SKU validation error. This issue occurs because products and their variants are soft-deleted and therefore the copied SKU will not be unique during the second cloning.

This change will allow multiple cloning and deleting of cloned products without an SKU validation error. This change uses the count of duplicated records in the SKU variants name. This will allow every record to be unique even if it is deleted.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

@Azeem838 Azeem838 force-pushed the fix-product-dup-bug branch 2 times, most recently from c034350 to 3d97f44 Compare October 4, 2021 11:46
@Azeem838 Azeem838 marked this pull request as ready for review October 4, 2021 13:37
Copy link
Member

@jarednorman jarednorman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a better solution be to scope the uniqueness validation to only non-discarded records? This can also be done at the database level by including the deleted_at column in the uniqueness constraint.

When a product is cloned and then discarded without changing the cloned
variants SKU, if the product is ever cloned again then the cloning
process will fail with a variant and master variant SKU validation
error. This issue occurs because products and their variants are soft
deleted and therefore the copied SKU will not be unique during the
second cloning.

The previous variant SKU uniqueness scope did not work for this specific
case so this conditional was added on top of it.

This commit also includes a validation spec for the variant SKU and a
spec to catch the deleted duplication error.
@Azeem838
Copy link
Contributor Author

Azeem838 commented Oct 5, 2021

@jarednorman Thanks for the review! Looking at the variant model, there seems to be an enforce_unique_sku? condition which was not being applied for this specific case.

I did not remove the enforce_unique_sku? condition since it might be still be used although the tests still pass without it. I need your advice as to whether to remove it or keep it as is.

@waiting-for-dev
Copy link
Contributor

This can also be done at the database level by including the deleted_at column in the uniqueness constraint.

I guess we can't do that, as we want that behavior to be configurable (i.e., at the application level)

I did not remove the enforce_unique_sku? condition since it might be still be used although the tests still pass without it. I need your advice as to whether to remove it or keep it as is.

I think we need to keep it, as it was added to let users override it.

@waiting-for-dev waiting-for-dev merged commit 92a4f0f into solidusio:master Jun 8, 2022
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.

None yet

3 participants