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

Migration error when using default currency that is not USD #3235

Closed
stephenmoloney opened this issue Nov 2, 2018 · 8 comments
Closed

Migration error when using default currency that is not USD #3235

stephenmoloney opened this issue Nov 2, 2018 · 8 comments

Comments

@stephenmoloney
Copy link
Contributor

stephenmoloney commented Nov 2, 2018

What I'm trying to achieve

When moving to new dockerhub saleor image 558de3985903133660e97d8a436b374c405a2fa1,
https://hub.docker.com/r/mirumee/saleor/tags/

Installation of saleor using a default currency that is not USD. In this case, DEFAULT_CURRENCY
was set to GBP

Steps to reproduce the problem

python3 manage.py migrate on a clean installation

What I expected to happen

I expected the migration to end successfully like previous saleor versions when DEFAULT_CURRENCY = GBP

Issue was resolved when DEFAULT_CURRENCY = USD

Error message

Operations to perform:
  Apply all migrations: account, auth, checkout, contenttypes, discount, django_celery_results, django_prices_openexchangerates, django_prices_vatlayer, impersonate, menu, order, page, payment, product, sessions, shipping, site, sites, social_django
Running migrations:
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 216, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 523, in alter_field
    old_db_params, new_db_params, strict)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/schema.py", line 122, in _alter_field
    new_db_params, strict,
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 627, in _alter_field
    new_default = self.effective_default(new_field)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 218, in effective_default
    default = field.get_default()
  File "/usr/local/lib/python3.6/site-packages/django_prices/models.py", line 59, in get_default
    return self.to_python(default)
  File "/usr/local/lib/python3.6/site-packages/django_prices/models.py", line 28, in to_python
    value.currency, self.currency))
ValueError: Invalid currency: 'GBP' (expected 'USD')

System information

Operating system: docker container
Browser: N/A

@stephenmoloney stephenmoloney changed the title Migration error when moving to new dockerhub saleor image Migration error when using default currency that is not USD Nov 2, 2018
@chrisfranklin
Copy link

Did you find a solution for this?

@stephenmoloney
Copy link
Contributor Author

@chrisfranklin Not yet, I'm a bit busy for about another week. I will look into this more in about a week. The same error does not occur on older versions of saleor.

@stephenmoloney
Copy link
Contributor Author

stephenmoloney commented Nov 19, 2018

@Pacu2
Have you encountered this issue?

It could be due to some changes in this commit:
c629988#diff-703f34f1c35686322145c8a0ae145792

I'm not really able to assess this easily.

@fredagsfys
Copy link

fredagsfys commented Nov 30, 2018

This is making our deployments painful as we need to set it to USD upon migration, then shift to SEK.
Is there a work-around/monkey-patch until fixed?

@adonig
Copy link

adonig commented Dec 1, 2018

I managed to fix this by replacing all occurrences of currency='USD' with currency='EUR' in all existing migrations. Thereafter python manage.py migrate successfully went through.

Because I read in another issue that it is necessary, I cascadingly truncated the order_order table before. So if the trick above doesn't work, try that (warning: it deletes all existing orders).

@Pacu2
Copy link
Contributor

Pacu2 commented Dec 1, 2018

How about replacing “USD” in migrations with “settings.DEFAULT_CURRENCY”? haven’t tried but should work tho

@NyanKiyoshi
Copy link
Member

Well, if I understand correctly, the issue occurs when that value gets changed by the user.

Assuming that the user is setting a environment variable, and not directly editing the settings.py file. The workaround would be no to set the environment variable DEFAULT_CURRENCY, so, to keep it to USD when generating migrations and migrating.

But, then, if the store currency is BTC for example, we would need to regenerate migrations because we would have to change the data precision. But in the case of GBP, that's not an issue to makemigrations/ migrate with USD instead.

@Pacu2
Copy link
Contributor

Pacu2 commented Dec 22, 2018

Resolved in #3506

@Pacu2 Pacu2 closed this as completed Dec 22, 2018
stephenmoloney added a commit to stephenmoloney/saleor-helm that referenced this issue Dec 22, 2018
What does this commit/MR/PR do?

- Update values for currency migrations fix
- Fix for issue `saleor/saleor#3235 by PR
`saleor/saleor#3506

Why is this commit/MR/PR needed?

- The currency migrations prior to this would break
stephenmoloney added a commit to stephenmoloney/saleor-helm that referenced this issue Jan 14, 2019
What does this commit/MR/PR do?

- Update values for currency migrations fix
- Fix for issue `saleor/saleor#3235 by PR
`saleor/saleor#3506

Why is this commit/MR/PR needed?

- The currency migrations prior to this would break
stephenmoloney added a commit to stephenmoloney/saleor-helm that referenced this issue Jan 14, 2019
What does this commit/MR/PR do?

- Update values for currency migrations fix
- Fix for issue `saleor/saleor#3235 by PR
`saleor/saleor#3506

Why is this commit/MR/PR needed?

- The currency migrations prior to this would break
stephenmoloney added a commit to stephenmoloney/saleor-helm that referenced this issue Jan 14, 2019
* Update values for currency migrations fix

What does this commit/MR/PR do?

- Update values for currency migrations fix
- Fix for issue `saleor/saleor#3235 by PR
`saleor/saleor#3506

Why is this commit/MR/PR needed?

- The currency migrations prior to this would break

* Update the version of the saleor image
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

No branches or pull requests

6 participants