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: PG::NotNullViolation (MAYBE-RAILS-CG) #1687

Closed
wants to merge 1 commit into from

Conversation

revise-dev[bot]
Copy link

@revise-dev revise-dev bot commented Jan 24, 2025

The error occurs because the uncategorized class method creates a new BudgetCategory instance without providing required values for budgeted_spending and currency, 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 requiring budgeted_spending and currency values.

Changes made:

  1. Added budgeted_spending: 0 to provide a sensible default for uncategorized items
  2. Added currency: budget&.currency || "USD" to inherit the currency from the associated budget if available, falling back to USD
  3. Made the method accept an optional budget parameter to properly set the currency

The 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:

  1. The uncategorized method creates a valid BudgetCategory
  2. The currency is inherited from the budget when provided
  3. The currency falls back to USD when no budget is provided
  4. The budgeted_spending is set to 0

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.

@zachgoll zachgoll closed this Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant