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: EXPOSED-292 Explicit nulls in insert with databaseGenerated() #1993

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

bog-walk
Copy link
Member

If a generated/computed column is marked as such using databaseGenerated(), but it is also nullable(), an exception is thrown even when the field is correctly excluded from an insert() block.

This occurs because a NULL value is still being auto-included for that column in the prepared insert statement.

Additional:

  • Add isDatabaseGenerated property to places where Column is copied, so that, for example, switching the chain order leads to equivalent results: .nullable().databaseGenerated() vs .databaseGenerated().nullable()

If a generated/computed column is marked as such using databaseGenerated(), but it is also nullable(), an exception is thrown even when the field is correctly excluded in an insert() block.

This occurs because a NULL value is still being auto-included for that column in the prepared insert statement.

This fix ensures that the column is excluded from adding an SQL NULL if it is marked
as database generated. The class property is also included wherever a column is copied
to ensure that swapping chained calls produces the same result.
@bog-walk bog-walk requested review from e5l and joc-a February 14, 2024 04:09
Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

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

good job, lgtm

@bog-walk bog-walk merged commit fa562d4 into main Feb 14, 2024
5 checks passed
@bog-walk bog-walk deleted the bog-walk/fix-nullable-database-generated branch February 14, 2024 18:18
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.

2 participants