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

Bug while update/migration: Duplicate Keyword and PropertyType found / but in different workspaces #2926

Closed
xolyu opened this issue Feb 2, 2024 · 1 comment

Comments

@xolyu
Copy link

xolyu commented Feb 2, 2024

Tandoor Version

1.5.12

Setup

Docker / Docker-Compose

Reverse Proxy

Others (please state below)

Other

Nginx

Bug description

I have tried to update Tandoor from version 1.4.8 to version 1.5.12.

I got the following errors:

RuntimeError: Duplicate Keyword found, please remove/rename them and run migrations again/restart the container. <QuerySet [{'name': 'Kuchen', 'name_count': 2}]>

Full Error - Click to expand
app-1    | Running migrations:
app-1    |   Applying account.0003_alter_emailaddress_create_unique_verified_email... OK
app-1    |   Applying account.0004_alter_emailaddress_drop_unique_email... OK
app-1    |   Applying account.0005_emailaddress_idx_upper_email... OK
app-1    |   Applying cookbook.0189_property_propertytype_unitconversion_food_fdc_id_and_more... OK
app-1    |   Applying cookbook.0190_auto_20230525_1506...Transforming nutrition information, this might take a while on large databases
app-1    |  OK
app-1    |   Applying cookbook.0191_foodproperty_property_import_food_id_and_more... OK
app-1    |   Applying cookbook.0192_food_food_unique_open_data_slug_per_space_and_more... OK
app-1    |   Applying cookbook.0193_space_internal_note... OK
app-1    |   Applying cookbook.0194_alter_food_properties_food_amount... OK
app-1    |   Applying cookbook.0195_invitelink_internal_note_userspace_internal_note_and_more... OK
app-1    |   Applying cookbook.0196_food_url... OK
app-1    |   Applying cookbook.0197_step_show_ingredients_table_and_more... OK
app-1    |   Applying cookbook.0198_propertytype_order... OK
app-1    |   Applying cookbook.0199_alter_propertytype_options_alter_automation_type_and_more... OK
app-1    | Traceback (most recent call last):
app-1    |   File "/opt/recipes/manage.py", line 15, in <module>
app-1    |     execute_from_command_line(sys.argv)
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
app-1    |     utility.execute()
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
app-1    |     self.fetch_command(subcommand).run_from_argv(self.argv)
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/base.py", line 412, in run_from_argv
app-1    |     self.execute(*args, **cmd_options)
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute
app-1    |     output = self.handle(*args, **options)
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/base.py", line 106, in wrapper
app-1    |     res = handle_func(*args, **kwargs)
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 356, in handle
app-1    |     post_migrate_state = executor.migrate(
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 135, in migrate
app-1    |     state = self._migrate_all_forwards(
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
app-1    |     state = self.apply_migration(
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
app-1    |     state = migration.apply(state, schema_editor)
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/migration.py", line 132, in apply
app-1    |     operation.database_forwards(
app-1    |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards
app-1    |     self.code(from_state.apps, schema_editor)
app-1    |   File "/opt/recipes/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py", line 23, in migrate_icons
app-1    |     raise RuntimeError(f'Duplicate Keyword found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
app-1    | RuntimeError: Duplicate Keyword found, please remove/rename them and run migrations again/restart the container. <QuerySet [{'name': 'Kuchen', 'name_count': 2}]>
app-1    |   Applying cookbook.0200_alter_propertytype_options_remove_keyword_icon_and_more...Generating static files

RuntimeError: Duplicate PropertyType found, please remove/rename them and run migrations again/restart the container. <QuerySet [{'name': 'Carbohydrates', 'name_count': 8}, {'name': 'Calories', 'name_count': 8}, {'name': 'Proteins', 'name_count': 8}, {'name': 'Fat', 'name_count': 8}]>

Full Error - Click to expand
app-1  | Running migrations:
app-1  | Traceback (most recent call last):
app-1  |   File "/opt/recipes/manage.py", line 15, in <module>
app-1  |     execute_from_command_line(sys.argv)
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
app-1  |     utility.execute()
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
app-1  |     self.fetch_command(subcommand).run_from_argv(self.argv)
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/base.py", line 412, in run_from_argv
app-1  |     self.execute(*args, **cmd_options)
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute
app-1  |     output = self.handle(*args, **options)
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/base.py", line 106, in wrapper
app-1  |     res = handle_func(*args, **kwargs)
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 356, in handle
app-1  |     post_migrate_state = executor.migrate(
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 135, in migrate
app-1  |     state = self._migrate_all_forwards(
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
app-1  |     state = self.apply_migration(
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
app-1  |     state = migration.apply(state, schema_editor)
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/migration.py", line 132, in apply
app-1  |     operation.database_forwards(
app-1  |   File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards
app-1  |     self.code(from_state.apps, schema_editor)
app-1  |   File "/opt/recipes/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py", line 28, in migrate_icons
app-1  |     raise RuntimeError(f'Duplicate PropertyType found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
app-1  | RuntimeError: Duplicate PropertyType found, please remove/rename them and run migrations again/restart the container. <QuerySet [{'name': 'Carbohydrates', 'name_count': 8}, {'name': 'Calories', 'name_count': 8}, {'name': 'Proteins', 'name_count': 8}, {'name': 'Fat', 'name_count': 8}]>
app-1  |   Applying cookbook.0200_alter_propertytype_options_remove_keyword_icon_and_more...Generating static files

It's correct, the Keyword Kuchen is 2 times in DB table cookbook_keyword and the PropertyTypes Carbohydrates, Calories, Proteins, Fat are 8 times in DB table cookbook_propertytype - But for different workspaces.

I think it is a bug that these values are detected as duplicates, because it must be possible to use the same keywords in different workspaces.

Image of the PropertyTypes DB table after I renamed the duplicates

grafik

After I manually renamed all the duplicates mentioned, the data migration was successful.

Migration log successful - Click to expand
app-1  | Running migrations:
app-1  |   Applying cookbook.0200_alter_propertytype_options_remove_keyword_icon_and_more... OK
app-1  |   Applying cookbook.0201_rename_date_mealplan_from_date_mealplan_to_date... OK
app-1  |   Applying cookbook.0202_remove_space_show_facet_count... OK
app-1  |   Applying cookbook.0203_alter_unique_contstraints... OK
app-1  |   Applying cookbook.0204_propertytype_fdc_id... OK
app-1  |   Applying cookbook.0205_alter_food_fdc_id_alter_propertytype_fdc_id... OK
app-1  |   Applying cookbook.0206_rename_sticky_navbar_userpreference_nav_sticky_and_more... OK
app-1  |   Applying cookbook.0207_space_logo_color_128_space_logo_color_144_and_more... OK
app-1  |   Applying cookbook.0208_space_app_name_userpreference_max_owned_spaces... OK
app-1  |   Applying cookbook.0209_remove_space_use_plural... OK
app-1  |   Applying oauth2_provider.0007_application_post_logout_redirect_uris... OK
app-1  |   Applying socialaccount.0004_app_provider_id_settings... OK
app-1  |   Applying socialaccount.0005_socialtoken_nullable_app... OK
app-1  |   Applying socialaccount.0006_alter_socialaccount_extra_data... OK
app-1  | Generating static files

I wonder, can I now undo the renaming, or will I have problems again with the next update?

Relevant logs

No response

@xolyu xolyu changed the title Bug while migration: Duplicate Keyword and PropertyType found / but in different workspaces Bug while update/migration: Duplicate Keyword and PropertyType found / but in different workspaces Feb 2, 2024
@vabene1111
Copy link
Collaborator

you are correct, I wanted to be smart and add an error message but forgot to filter for spaces. I fixed it to properly take spaces into account.

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

2 participants