Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG] Product options null value returns 400 instead of 500#12501

Merged
lchrusciel merged 3 commits into
Sylius:1.8from
SirDomin:product-options-null-value
Apr 1, 2021
Merged

[BUG] Product options null value returns 400 instead of 500#12501
lchrusciel merged 3 commits into
Sylius:1.8from
SirDomin:product-options-null-value

Conversation

@SirDomin
Copy link
Copy Markdown
Contributor

@SirDomin SirDomin commented Apr 1, 2021

Q A
Branch? 1.8
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets
License MIT

@SirDomin SirDomin requested a review from a team as a code owner April 1, 2021 06:01
@SirDomin SirDomin added API APIs related issues and PRs. Bug Confirmed bugs or bugfixes. labels Apr 1, 2021
@SirDomin SirDomin changed the title [BUG] Product options null value [BUG] Product options null value returns 400 instead of 500 Apr 1, 2021
Comment thread tests/Controller/ProductVariantApiTest.php Outdated
@SirDomin SirDomin force-pushed the product-options-null-value branch from 201c765 to 78c165d Compare April 1, 2021 11:34
Comment thread src/Sylius/Component/Product/Model/ProductVariant.php Outdated
public function removeOptionValue(ProductOptionValueInterface $optionValue): void;

public function hasOptionValue(ProductOptionValueInterface $optionValue): bool;
public function hasOptionValue(?ProductOptionValueInterface $optionValue): bool;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if this change is not a BC Break, although it expands the accepted argument, wdyt @lchrusciel

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 That's a BC break, all classes implementing this interface have to change their method signature.

@SirDomin SirDomin force-pushed the product-options-null-value branch from 78c165d to 2eedf53 Compare April 1, 2021 11:56
@SirDomin SirDomin force-pushed the product-options-null-value branch from 2eedf53 to e11571e Compare April 1, 2021 13:48
public function hasOptionValue(?ProductOptionValueInterface $optionValue): bool
{
return $this->optionValues->contains($optionValue);
return $optionValue === null ? true : $this->optionValues->contains($optionValue);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why true instead of false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is abit tricky, because by returning true we force it ProductVariant to dont allow null as argument and handle it as bad request.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is tricky because it feels wrong to check whether a product variant has an option value null. I think we should fix it upstream and do not let null to be passed to this method in the first place.

@lchrusciel lchrusciel merged commit f2e95c0 into Sylius:1.8 Apr 1, 2021
@lchrusciel
Copy link
Copy Markdown
Contributor

Thank you, @SirDomin! 🥇

pamil added a commit that referenced this pull request Apr 9, 2021
This PR was merged into the 1.8 branch.

Discussion
----------

Introduced in #12501.

Commits
-------

67bf126 Revert BC break in ProductVariantInterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API APIs related issues and PRs. Bug Confirmed bugs or bugfixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants