Skip to content

Pass db_session to user delete method#3509

Open
guptapratykshh wants to merge 3 commits intoaugurlabs:mainfrom
guptapratykshh:fix/delete-account-2672
Open

Pass db_session to user delete method#3509
guptapratykshh wants to merge 3 commits intoaugurlabs:mainfrom
guptapratykshh:fix/delete-account-2672

Conversation

@guptapratykshh
Copy link
Copy Markdown
Contributor

@guptapratykshh guptapratykshh commented Jan 6, 2026

Description
This PR fixes a critical bug where users attempting to delete their accounts would encounter a 500 Internal Server Error. The root cause was that the user_delete() route handler was calling current_user.delete() without passing the required session parameter.

  • Fixed user_delete() function in augur/api/view/routes.py to pass db_session parameter to User.delete() method
  • Added try-except error handling to prevent unhandled exceptions
  • Added error logging for better debugging and issue tracking
  • Stored username before deletion to ensure success message displays correctly

This PR fixes #2672

Notes for Reviewers

Signed commits

  • Yes, I signed my commits.

@guptapratykshh guptapratykshh force-pushed the fix/delete-account-2672 branch 3 times, most recently from 2c82017 to a08dd38 Compare January 6, 2026 13:18
@guptapratykshh guptapratykshh force-pushed the fix/delete-account-2672 branch from ba588f4 to 1e7fa95 Compare January 7, 2026 16:36
@guptapratykshh guptapratykshh force-pushed the fix/delete-account-2672 branch 2 times, most recently from 8df7eb0 to 0cf49f2 Compare January 8, 2026 06:49
@guptapratykshh
Copy link
Copy Markdown
Contributor Author

Reverted all the imports and else block that were removed , please review the PR @MoralCode

@MoralCode
Copy link
Copy Markdown
Collaborator

Code looks good! Just make sure to rebase your changes.

Id also be curious how this was tested/get a couple maintainers to give it the thumbs up. Overall looks like this is very close to being able to ship!

@guptapratykshh guptapratykshh force-pushed the fix/delete-account-2672 branch from 0cf49f2 to 51d3688 Compare January 9, 2026 20:39
@guptapratykshh
Copy link
Copy Markdown
Contributor Author

I tested this by checking the code (the User.delete() method needs a session parameter that wasn't being passed) and writing a mock test to verify the fix works correctly.

Also the docker build failure is not related to this PR. It is CI issue with the geckodriver download because gitHub API returned null. Rerunning the build should fix it.

@guptapratykshh guptapratykshh force-pushed the fix/delete-account-2672 branch from 0a52048 to 4793eaf Compare January 12, 2026 04:33
@MoralCode MoralCode added this to the v0.93.0 milestone Jan 21, 2026
else:
logger.error(f"Failed to delete account {username}: {result[1]}")
flash("An error occurred removing the account")
except Exception as e:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should we roll back the transaction here if an error happens?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looking at User.delete() - it calls session.commit() internally at the end. If an exception is raised before that commit, the changes aren't persisted anyway.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But I guess explicitly calling session.rollback() would be cleaner to reset the session state? That said, since db_session is a scoped session in, it should handle cleanup on the next request. So it's not strictly necessary.

@MoralCode MoralCode added the discussion Seeking active feedback, usually for items under active development label Feb 4, 2026
@MoralCode MoralCode requested a review from shlokgilda February 4, 2026 18:21
@MoralCode
Copy link
Copy Markdown
Collaborator

I verified this by .... writing a mock test to verify the fix works correctly.

Is that test included?

Copy link
Copy Markdown
Collaborator

@shlokgilda shlokgilda left a comment

Choose a reason for hiding this comment

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

Looks good overall. Just a nitpick comment about logger.

else:
logger.error(f"Failed to delete account {username}: {result[1]}")
flash("An error occurred removing the account")
except Exception as e:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But I guess explicitly calling session.rollback() would be cleaner to reset the session state? That said, since db_session is a scoped session in, it should handle cleanup on the next request. So it's not strictly necessary.

logger.error(f"Failed to delete account {username}: {result[1]}")
flash("An error occurred removing the account")
except Exception as e:
logger.error(f"Exception occurred while deleting account: {e}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: including the username in the exception log would help correlate errors with specific users during debugging

logger.error(f"Exception occurred while deleting account {username}: {e}")

@MoralCode
Copy link
Copy Markdown
Collaborator

Hello! Just wanted to check in to see if you were still interested in helping the maintainers merge this PR. We noticed it has been a little while since this last had activity, and are considering closing it or taking it over if it remains in its current state.

Please react to or reply to this to confirm your interest in the next 7 days or let us know if you are no longer interested in this so we can best prioritize everyone's contributions.

Thanks!

@MoralCode MoralCode added the stale Stuff that's abandoned or not making forward progress and may need taking over/reassignment/closing label Feb 9, 2026
@MoralCode MoralCode modified the milestones: v0.93.0, v0.94.0 Mar 6, 2026
@MoralCode MoralCode changed the title Fix #2672: Pass db_session to user delete method Pass db_session to user delete method Mar 16, 2026
@MoralCode MoralCode force-pushed the fix/delete-account-2672 branch from 9728436 to 4aefc7a Compare March 16, 2026 19:35
@MoralCode MoralCode requested a review from Ulincsys as a code owner March 16, 2026 19:35
- Pass required db_session parameter to current_user.delete()
- Add try-except block for proper exception handling
- Store username before deletion for accurate flash message
- Add error logging for debugging failed deletions

Signed-off-by: Pratyksh Gupta <pratykshgupta9999@gmail.com>
Signed-off-by: guptapratykshh <pratykshgupta9999@gmail.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
@MoralCode MoralCode force-pushed the fix/delete-account-2672 branch from 4aefc7a to 7e90eaa Compare March 16, 2026 19:37
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
Signed-off-by: Adrian Edwards <adredwar@redhat.com>
@MoralCode MoralCode force-pushed the fix/delete-account-2672 branch from 7e90eaa to 0da33d7 Compare March 16, 2026 19:38
@MoralCode
Copy link
Copy Markdown
Collaborator

Taking this over as it is a relatively straightforward fix to a known, reproducible bug and the original submitter has not responded

@MoralCode MoralCode removed the stale Stuff that's abandoned or not making forward progress and may need taking over/reassignment/closing label Mar 16, 2026
@MoralCode MoralCode self-assigned this Mar 16, 2026
@@ -198,10 +198,11 @@ def authorize_user():
@app.route('/account/delete')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not from this PR, but user_delete is on a GET route. Might be worth a follow-up to change this to POST.

flash(f"Account {current_user.login_name} successfully removed")
logout_user()
else:
logger.error(f"Exception occurred while deleting account {current_user.login_name}: {e}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There's no try/except (e will be undefined). Either wrap the delete in a try/except or just drop the logger line.

flash(f"Account {current_user.login_name} successfully removed")
logout_user()
else:
logger.error(f"Exception occurred while deleting account {current_user.login_name}: {e}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

current_user.login_name might not be valid after delete() since it commits the row deletion internally. Capture the username before calling delete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discussion Seeking active feedback, usually for items under active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delete account fails

3 participants