-
Notifications
You must be signed in to change notification settings - Fork 78
[Namespacing] Refactor UserSession to User::Session
#12294
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
base: main
Are you sure you want to change the base?
Conversation
UserSession to User::SessionUserSession to User::Session
| class UpdateUserSessionTypes < ActiveRecord::Migration[8.0] | ||
| def up | ||
| PublicActivity::Activity.where(trackable_type: "UserSession").update_all(trackable_type: "User::Session") | ||
| PaperTrail::Version.where(item_type: "UserSession").update_all(item_type: "User::Session") | ||
| end | ||
|
|
||
| def down | ||
| PublicActivity::Activity.where(trackable_type: "User::Session").update_all(trackable_type: "UserSession") | ||
| PaperTrail::Version.where(item_type: "User::Session").update_all(item_type: "UserSession") | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Deployment order issue: NameError when trackable_type = "UserSession" is constantized before migration runs.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The trackable_is_deletable? method calls constantize on trackable_type. If the new code is deployed before the migration db/migrate/20251208174819_update_user_session_types.rb runs, activity records with trackable_type = "UserSession" will still exist. Since UserSession is removed, calling "UserSession".constantize raises a NameError, causing pages displaying activities (e.g., /my, event audit logs) to crash.
💡 Suggested Fix
Ensure the migration db/migrate/20251208174819_update_user_session_types.rb is run and completed in production before deploying the new code that removes the UserSession class.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: db/migrate/20251208174819_update_user_session_types.rb#L1-L11
Potential issue: The `trackable_is_deletable?` method calls `constantize` on
`trackable_type`. If the new code is deployed before the migration
`db/migrate/20251208174819_update_user_session_types.rb` runs, activity records with
`trackable_type = "UserSession"` will still exist. Since `UserSession` is removed,
calling `"UserSession".constantize` raises a `NameError`, causing pages displaying
activities (e.g., `/my`, event audit logs) to crash.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 6234838

Summary of the problem
Describe your changes