fix(schema): default invPaid to false so bulk-create doesn't trip NOT NULL#279
Merged
Merged
Conversation
… NULL Same drift class as #265 (custState) and #277 (custCompanyName et al.), but with a twist: the single-create controller already filled in the missing-invPaid case with \`if (payload.invPaid === undefined) payload.invPaid = false;\`, so the bug only manifested in the bulk path, which routes through \`makeBulkCreateIndirect\` and doesn't have entity-specific defaults. A bulk POST like { invoices: [{ invCustId: 5, invDate: "2026-01-01", invDueDate: "2026-02-01" }] } passed the schema (invPaid was \`.optional()\`), and then tripped "null value in column invPaid violates not-null constraint" at the postgres INSERT — surfacing as a 500 instead of a clean accepted row. Switching the schema to \`z.boolean().default(false)\` fills the value at the validator boundary, so both paths now get \`invPaid: false\` for free. The single-create controller's explicit default becomes dead defense but stays harmless. 760 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Same drift class as #265 (custState) and #277 (custCompanyName et al.), but with a twist: the single-create invoice controller already short-circuited a missing
invPaidtofalseinline, so the bug only manifested in the bulk path (makeBulkCreateIndirect), which doesn't apply entity-specific defaults.A bulk POST like
{ "invoices": [{ "invCustId": 5, "invDate": "2026-01-01", "invDueDate": "2026-02-01" }] }passed the zod schema (
invPaidwas.optional()) and then tripped"null value in column invPaid violates not-null constraint"at the postgres INSERT — surfacing as a 500 instead of a clean accepted row.What changed
Switched the schema to
z.boolean().default(false). The validator now fills the value at the request boundary, so both paths (single + bulk) getinvPaid: falsefor free. The single-create controller's explicit default-to-false line is now dead defense but stays harmless.Test plan
npm run lint && npm test— 760 passing.Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/