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

OBPIH-4896 Handle already existing product type with empty code and product identifier #3541

Conversation

drodzewicz
Copy link
Collaborator

No description provided.

@@ -196,6 +196,14 @@ class ProductController {

updateTags(productInstance, params)

ProductType defaultProductType = ProductType.defaultProductType.list()?.first();
// Throw an error for product type with empty code and product identifier that is not a default product type
if (productInstance.productType != defaultProductType && !productInstance.productType?.code && !productInstance.productType?.productIdentifierFormat) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm just wondering if you can compare productInstance.productType to defaultProductType using equality comparator - even if they are of the same class and have the same properties and keys, will the reference be the same, so you can compare objects?
I believe in JS it wouldn't work ({} === {} would return false), but does it work in Groovy and you were aware of that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes it was intentional and it does work as intended.

Copy link
Collaborator

Choose a reason for hiding this comment

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

cool, then JS just sucks in this case :D

Copy link
Member

Choose a reason for hiding this comment

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

This is a good point. And generally depends on the equals() implementation.

https://stackoverflow.com/questions/28500091/grails-gorm-what-is-the-default-equals-implementation-in-gorm

In general, we're probably ok. But I've seen cases where this doesn't do the right thing so it's better to compare primitives (productType.id) or implement equals.

We already have the "equals / hashCode" issue on our tech debt pile so I might do this to be on the safe side.

productInstance?.productType?.id != defaultProductType?.id

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah you guys have a good point.
Just to be on the safe lets compare primitive values to avoid potential bugs.

Copy link
Member

Choose a reason for hiding this comment

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

@drodzewicz I'll merge it for now since we want to get these obdev, but please remember to make and test that change when you get a chance.

@@ -196,6 +196,14 @@ class ProductController {

updateTags(productInstance, params)

ProductType defaultProductType = ProductType.defaultProductType.list()?.first();
// Throw an error for product type with empty code and product identifier that is not a default product type
if (productInstance.productType != defaultProductType && !productInstance.productType?.code && !productInstance.productType?.productIdentifierFormat) {
Copy link
Member

Choose a reason for hiding this comment

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

This is a good point. And generally depends on the equals() implementation.

https://stackoverflow.com/questions/28500091/grails-gorm-what-is-the-default-equals-implementation-in-gorm

In general, we're probably ok. But I've seen cases where this doesn't do the right thing so it's better to compare primitives (productType.id) or implement equals.

We already have the "equals / hashCode" issue on our tech debt pile so I might do this to be on the safe side.

productInstance?.productType?.id != defaultProductType?.id

@jmiranda jmiranda merged commit 2a06f7e into develop Oct 13, 2022
@jmiranda jmiranda deleted the OBPIH-4896-handle-already-existing-product-type-with-empty-code-and-product-identifier branch October 13, 2022 03:15
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