Fix: PG::NotNullViolation (MAYBE-RAILS-CG) #1687
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The error occurs because the
uncategorized
class method creates a new BudgetCategory instance without providing required values forbudgeted_spending
andcurrency
, which are defined as NOT NULL in the database schema. This likely occurs when the application needs to handle transactions or budget items that don't have a specific category assigned.The original intent of the
uncategorized
method was to create a special BudgetCategory instance with a UUID generated from the string "uncategorized" and no associated category. However, it didn't account for the database constraints requiringbudgeted_spending
andcurrency
values.Changes made:
budgeted_spending: 0
to provide a sensible default for uncategorized itemscurrency: budget&.currency || "USD"
to inherit the currency from the associated budget if available, falling back to USDThe changes maintain the original functionality while ensuring database constraints are met. The default value of 0 for budgeted_spending makes sense since uncategorized items typically don't have a planned budget.
Tests should be added to verify:
Tip
You can make revisions or ask questions of Revise.dev by using
/revise
in any comment or review!/revise Add a comment above the method to explain why we're making this change.
/revise Why did you choose to make this change specifically?
Important
If something doesn't look right, click to retry this interaction.