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 default game fallback in _restore_game_info #264

Merged
merged 2 commits into from
May 28, 2020

Conversation

DasSkelett
Copy link
Member

Problem

Noticed the following error in the syslog when navigating to the mod update upload page on alpha:

 2020-05-22 11:02:31,965 ERROR Backend:30011 Exception on /mod/3/Test download path/update [GET]
 Traceback (most recent call last):
   File "/var/www/virtual/spacedock.info/htdocs/SpaceDock/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1283, in _execute_context
     self.dialect.do_execute(
   File "/var/www/virtual/spacedock.info/htdocs/SpaceDock/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
     cursor.execute(statement, parameters)
 psycopg2.errors.InvalidTextRepresentation: invalid input syntax for integer: "kerbal-space-program"
 LINE 3: WHERE game.id = 'kerbal-space-program' ORDER BY game.id DESC...

<some more messages and lines and stuff>

   File "/var/www/virtual/spacedock.info/htdocs/SpaceDock/KerbalStuff/blueprints/mods.py", line 62, in update
     ga = _restore_game_info()
   File "/var/www/virtual/spacedock.info/htdocs/SpaceDock/KerbalStuff/blueprints/mods.py", line 40, in _restore_game_info
     ga = Game.query.filter(Game.id == game_id).order_by(desc(Game.id)).first()

If users have no game assigned to their current session, _restore_game_info() tries to default to KSP.
However, it assigns the game's short instead of the id to the game_id variable, and then the DB throws a type error.

The return value hasn't been used in update.html, and in create.html only for setting the default selection I think.

Changes

_restore_game_info() is now changed to properly fallback to KSP (based on the short).

The call to _restore_game_info() is removed from update() since it isn't needed, the game is also no longer passed to the template.

In api.update_mod a query filter has been changed to compare against mod.game_id instead of Mod.game_id. Not sure why this even worked, I guess SQLAlchemy has some special logic for comparing to classes/table columns, and just tests if the columns are of the same type or something.

The game parameter for create.html has been renamed to games, since it's a list of games, not a single one.

@DasSkelett DasSkelett added Type: Bug Area: Backend Related to the Python code that runs inside gunicorn Priority: Low Area: Frontend Related to HTML, JS, CSS, or other browser things labels May 22, 2020
Copy link
Contributor

@HebaruSan HebaruSan left a comment

Choose a reason for hiding this comment

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

That makes a lot more sense now.

@HebaruSan HebaruSan merged commit b7cb750 into KSP-SpaceDock:alpha May 28, 2020
@DasSkelett DasSkelett deleted the fix/restore-game-info branch May 28, 2020 21:11
HebaruSan pushed a commit that referenced this pull request Jun 3, 2020
* Fix default game fallback in _restore_game_info

* Don't default to KSP at mod creation
@HebaruSan HebaruSan mentioned this pull request Jun 28, 2020
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: Frontend Related to HTML, JS, CSS, or other browser things Priority: Low Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants