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

Fix attribute error when saving mod that was in deleted modpack #380

Merged
merged 1 commit into from
Aug 13, 2021

Conversation

HebaruSan
Copy link
Contributor

@HebaruSan HebaruSan commented Jul 30, 2021

Problem

  1. Create a mod pack
  2. Add a mod
  3. Delete the mod pack
  4. Try to edit the mod from step 2
  5. Save your changes
  6. image
    image

Cause

In #368 we added some code that assumes that ModListItem.mod_list_id won't be NULL.

score += 15 * len({itm.mod_list for itm in mod.mod_list_items if itm.mod_list.user_id != mod.user_id})

However, when you delete a mod list, its ModListItems are not deleted but simply have their mod_list_id set to NULL.

spacedock=# select * from modlistitem;
 id | mod_id | mod_list_id | sort_index 
----+--------+-------------+------------
  1 |      1 |             |          0
  2 |      2 |             |          1
  3 |      3 |             |          2
  4 |      3 |             |          0
  6 |      2 |             |          1
  5 |      1 |           4 |          0
  7 |      2 |           4 |          1
  8 |      3 |           6 |          0
  9 |      5 |           4 |          2
 10 |      6 |           4 |          3
(10 rows)

Each such row represents a case where Mod.mod_list_items[X].mod_list is None for some mod.

Changes

  • Now all ModListItems from deleted mod lists are deleted
  • Now ModListItem.mod_id is non-nullable and has cascade deletion enabled
  • Now ModListItem.mod_list_id is non-nullable and has cascade deletion enabled
  • Now ModListItem.sort_index is non-nullable

After this, the code from #368 will be correct that ModListItem.mod_list_id won't be NULL.

@HebaruSan HebaruSan added Type: Bug Area: Backend Related to the Python code that runs inside gunicorn Priority: Blocking Status: Ready Area: Migration Related to Alembic database migrations labels Jul 30, 2021
@HebaruSan HebaruSan requested a review from DasSkelett July 31, 2021 17:54
Copy link
Member

@DasSkelett DasSkelett left a comment

Choose a reason for hiding this comment

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

Thanks, works perfectly! non-nullable-ify all the things!

@DasSkelett DasSkelett merged commit c7556d9 into KSP-SpaceDock:alpha Aug 13, 2021
@HebaruSan HebaruSan deleted the fix/mod-score-attrib-err branch August 13, 2021 13:18
This was referenced Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Backend Related to the Python code that runs inside gunicorn Area: Migration Related to Alembic database migrations Priority: Blocking Status: Ready Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants