You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Processors::Product finds or initializes a new product based on the @data["Handle"]. Then, later on, it assigns the slug again to the @data["Handle"]. This is normally not a problem. In a recent import, however, we came across a handle/slug data issue that was difficult to debug. We think this is due to how Solidus generates valid slugs from invalid input.
Reproduction steps
Here's how you can reproduce:
In your product import CSV, add a Handle with an invalid character. i.e. arts-&-crafts-box
Run the product import.
Check the slug of the created product. (It should be arts-crafts-box.)
Run the import again.
Current behaviour
A new product is initialized for arts-&-crafts-box, then the slug is re-generated to be arts-crafts-box, and we end up with a ActiveRecord::InvalidRecordSlug has already been taken error.
Expected behaviour
The arts-crafts-box product is found and loaded. No new product is initialized.
Solution
I am not sure what the best solution would be. Perhaps there is a more nuanced problem in Solidus where Product.find_or_initialize_by(slug: slug) is not the best way to find or initialize a product.
I think at the very least we could validate that the slug input in the CSV would be a valid slug as written. In this example, the first import would complete successfully, but the user would expect their product to be at /product/arts-&-crafts-box and they might be confused and think their import didn't work. The user's second import would fail, and it would be hard for them to figure out why.
The text was updated successfully, but these errors were encountered:
Hey Ben! What if we just report this as a specific importing error? Users will figure out why this happens and change the CSV based on what they want to do. What do you think?
This issue has been automatically marked as stale because it has not had recent activity. It might be closed if no further activity occurs. Thank you for your contributions.
Processors::Product
finds or initializes a new product based on the@data["Handle"]
. Then, later on, it assigns the slug again to the@data["Handle"]
. This is normally not a problem. In a recent import, however, we came across a handle/slug data issue that was difficult to debug. We think this is due to how Solidus generates valid slugs from invalid input.Reproduction steps
Here's how you can reproduce:
Handle
with an invalid character. i.e.arts-&-crafts-box
arts-crafts-box
.)Current behaviour
A new product is initialized for
arts-&-crafts-box
, then the slug is re-generated to bearts-crafts-box
, and we end up with aActiveRecord::InvalidRecord
Slug has already been taken
error.Expected behaviour
The
arts-crafts-box
product is found and loaded. No new product is initialized.Solution
I am not sure what the best solution would be. Perhaps there is a more nuanced problem in Solidus where
Product.find_or_initialize_by(slug: slug)
is not the best way to find or initialize a product.I think at the very least we could validate that the slug input in the CSV would be a valid slug as written. In this example, the first import would complete successfully, but the user would expect their product to be at
/product/arts-&-crafts-box
and they might be confused and think their import didn't work. The user's second import would fail, and it would be hard for them to figure out why.The text was updated successfully, but these errors were encountered: