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

Do not allow prices with nil amount #3987

Merged

Conversation

waiting-for-dev
Copy link
Contributor

Description

This overtolerance was introduced in 58ec5cd. That commit introduced
the Spree::Price model to allow dealing with multiple currencies. It
allowed amount to be nil for master variants, variants with no
master variant, and variants with a master variant with no price. AFAIK,
these three scenarios are no considered by our business logic.

In fact, the logic was removed 5 days later in 9d563e3.

58ec5cd also allowed for amount to be nil in any other case, but
then it copied it from the master variant:

9d563e3#diff-c083f45179b62dc8c47e4fdcbf7ee31da80552100fc0258238817086e46e2925L35

However, this was also done in the controller layer and it's still in
place:

@object.default_price = @object.product.master.default_price.clone

Please, tell me if you'd prefer a less aggressive migration process.

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)

@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/dont_allow_nil_amount branch from 041d7c9 to 3eb9fd4 Compare March 12, 2021 06:59
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

@waiting-for-dev great work, I think it makes sense. I'd move the data migration into a rake task (something similar to what we did for 2.11).

Please also take a look at the specs against older versions of Rails in the CI.

core/spec/models/spree/price_spec.rb Show resolved Hide resolved
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/dont_allow_nil_amount branch from 3eb9fd4 to 43dfcb2 Compare March 12, 2021 16:58
@waiting-for-dev
Copy link
Contributor Author

@waiting-for-dev great work, I think it makes sense. I'd move the data migration into a rake task (something similar to what we did for 2.11).

Yeah, I agree it's a better solution. I did it in a task named matching 3.0 version. Please, tell me if I should address another version.

Please also take a look at the specs against older versions of Rails in the CI.

Hmm.. all the failures reference a spree_user_key column which seems not related to the work here... Do you know what is it about?

screenshot-app circleci com-2021 03 12-18_01_56

@kennyadsl
Copy link
Member

@waiting-for-dev I think the CI errors are due to the way migration has been defined: you are using ActiveRecord::Migration[6.1] as the parent class and this is preventing it to work in old versions. Please take a look at the other migrations as a reference.

This logic will help in an upcoming work that will copy all prices from
a master variant over its children variant (thus enforcing that no
"empty" prices are created).

This overtolerance was introduced in 58ec5cd. That commit introduced
the `Spree::Price` model to allow dealing with multiple currencies. It
allowed `amount` to be `nil` for master variants, variants with no
master variant, and variants with a master variant with no price. AFAIK,
these three scenarios are no considered by our business logic.

In fact, the logic was removed 5 days later in 9d563e3.

58ec5cd also allowed for `amount` to be `nil` in any other case, but
then it copied it from the master variant:

solidusio@9d563e3#diff-c083f45179b62dc8c47e4fdcbf7ee31da80552100fc0258238817086e46e2925L35

However, this was also done in the controller layer and it's still in
place:

https://github.com/solidusio/solidus/blob/3cc2d3e492b0aa6c84ac66814db26bea4f17d2e0/backend/app/controllers/spree/admin/variants_controller.rb#L19
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/dont_allow_nil_amount branch from 43dfcb2 to 286d0e3 Compare March 15, 2021 17:24
@waiting-for-dev
Copy link
Contributor Author

@waiting-for-dev I think the CI errors are due to the way migration has been defined: you are using ActiveRecord::Migration[6.1] as the parent class and this is preventing it to work in old versions. Please take a look at the other migrations as a reference.

Thanks @kennyadsl , it seems everything is fine now 👍

Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@waiting-for-dev thanks for this change, I think it makes total sense. I left a few comments on renaming the rake task, I believe there's a small typo in the name that may be worth addressing.

core/lib/tasks/upgrade.rake Outdated Show resolved Hide resolved
@waiting-for-dev
Copy link
Contributor Author

@waiting-for-dev thanks for this change, I think it makes total sense. I left a few comments on renaming the rake task, I believe there's a small typo in the name that may be worth addressing.

Thanks for reviewing it @spaghetticode The typo is fixed now 👍

@spaghetticode
Copy link
Member

@waiting-for-dev thank you!

I think the spec file needs renaming: core/spec/lib/tasks/migrations/delete_prices_with_nul_amount_spec.rb -> core/spec/lib/tasks/migrations/delete_prices_with_nil_amount_spec.rb

@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/dont_allow_nil_amount branch from dff7700 to 2982058 Compare April 12, 2021 15:08
@waiting-for-dev
Copy link
Contributor Author

I think the spec file needs renaming: core/spec/lib/tasks/migrations/delete_prices_with_nul_amount_spec.rb -> core/spec/lib/tasks/migrations/delete_prices_with_nil_amount_spec.rb

🤦 thanks @spaghetticode , fixed 🙈

Copy link
Member

@gmacdougall gmacdougall left a comment

Choose a reason for hiding this comment

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

This makes sense. I don't think we should have prices with nil amounts.

Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

Thanks @waiting-for-dev 👍

@kennyadsl kennyadsl added changelog:solidus_core Changes to the solidus_core gem and removed Needs Core Team Review labels Sep 1, 2021
@kennyadsl kennyadsl merged commit ea200df into solidusio:master Sep 1, 2021
@kennyadsl kennyadsl deleted the waiting-for-dev/dont_allow_nil_amount branch September 1, 2021 14:08
waiting-for-dev added a commit to nebulab/solidus that referenced this pull request Sep 6, 2021
… generator

Having both an `upgrade` task and an `update` generator is confusing. On
top of that, it's better to have actionable items, which can be
undesirable in some situations, the most explicit as possible. For this
reason, we leave in place the `update` generator, which is just a safe
path to update preferences, and remove the `upgrade` task. Instead, we
add a generic message into the `update` generator pointing to the
detailed instructions in the Changelog.

In particular, at this point, the `update` task was calling to a single
task introduced in solidusio#3987. We still keep the task reachable by end-users,
but we rename it slightly to be more friendly.
waiting-for-dev added a commit to nebulab/solidus that referenced this pull request Sep 6, 2021
… generator

Having both an `upgrade` task and an `update` generator is confusing. On
top of that, it's better to have actionable items, which can be
undesirable in some situations, the most explicit as possible. For this
reason, we leave in place the `update` generator, which is just a safe
path to update preferences, and remove the `upgrade` task. Instead, we
add a generic message into the `update` generator pointing to the
detailed instructions in the Changelog.

In particular, at this point, the `update` task was calling to a single
task introduced in solidusio#3987. We still keep the task reachable by end-users,
but we rename it slightly to be more friendly.
biximilien pushed a commit to biximilien/solidus that referenced this pull request Sep 9, 2021
… generator

Having both an `upgrade` task and an `update` generator is confusing. On
top of that, it's better to have actionable items, which can be
undesirable in some situations, the most explicit as possible. For this
reason, we leave in place the `update` generator, which is just a safe
path to update preferences, and remove the `upgrade` task. Instead, we
add a generic message into the `update` generator pointing to the
detailed instructions in the Changelog.

In particular, at this point, the `update` task was calling to a single
task introduced in solidusio#3987. We still keep the task reachable by end-users,
but we rename it slightly to be more friendly.
rmparr pushed a commit to rmparr/solidus that referenced this pull request Jun 1, 2022
… generator

Having both an `upgrade` task and an `update` generator is confusing. On
top of that, it's better to have actionable items, which can be
undesirable in some situations, the most explicit as possible. For this
reason, we leave in place the `update` generator, which is just a safe
path to update preferences, and remove the `upgrade` task. Instead, we
add a generic message into the `update` generator pointing to the
detailed instructions in the Changelog.

In particular, at this point, the `update` task was calling to a single
task introduced in solidusio#3987. We still keep the task reachable by end-users,
but we rename it slightly to be more friendly.
rmparr pushed a commit to rmparr/solidus that referenced this pull request Jun 1, 2022
… generator

Having both an `upgrade` task and an `update` generator is confusing. On
top of that, it's better to have actionable items, which can be
undesirable in some situations, the most explicit as possible. For this
reason, we leave in place the `update` generator, which is just a safe
path to update preferences, and remove the `upgrade` task. Instead, we
add a generic message into the `update` generator pointing to the
detailed instructions in the Changelog.

In particular, at this point, the `update` task was calling to a single
task introduced in solidusio#3987. We still keep the task reachable by end-users,
but we rename it slightly to be more friendly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants