Skip to content

Conversation

@Newbie012
Copy link
Collaborator

@Newbie012 Newbie012 commented Nov 13, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where custom type inference was incorrect when used with custom column overrides.
  • Tests

    • Added test coverage for type and column override scenarios.

Fix the logic for resolving custom type overrides to ensure that type overrides are applied correctly even when column overrides exist for unrelated columns. Previously, the code returned early when a column override was found, ignoring type overrides that should apply to the column's type. This caused incorrect early exit and improper type resolution. The fix changes the order of checks to first look for a column override for the specific column, and if none is found, then apply the type override for the column's type. Added a test to verify that type overrides are respected even when unrelated column overrides exist.
@Newbie012 Newbie012 enabled auto-merge (squash) November 13, 2025 22:55
@changeset-bot
Copy link

changeset-bot bot commented Nov 13, 2025

🦋 Changeset detected

Latest commit: 90bacd2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@ts-safeql/generate Patch
@ts-safeql/eslint-plugin Patch
@ts-safeql/shared Patch
@ts-safeql/sql-ast Patch
@ts-safeql-demos/basic-flat-config Patch
@ts-safeql-demos/basic-migrations-raw Patch
@ts-safeql-demos/basic-transform-type Patch
@ts-safeql-demos/basic Patch
@ts-safeql-demos/big-project Patch
@ts-safeql-demos/config-file-flat-config Patch
@ts-safeql-demos/from-config-file Patch
@ts-safeql-demos/multi-connections Patch
@ts-safeql-demos/playground Patch
@ts-safeql-demos/postgresjs-custom-types Patch
@ts-safeql-demos/postgresjs-demo Patch
@ts-safeql-demos/vercel-postgres Patch
@ts-safeql/test-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Nov 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
safeql Ignored Ignored Preview Nov 13, 2025 11:00pm

@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2025

Warning

Rate limit exceeded

@Newbie012 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 6 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3bf5693 and 90bacd2.

📒 Files selected for processing (1)
  • packages/generate/src/generate.ts (1 hunks)

Walkthrough

This PR fixes an issue with custom type inference when used with custom column overrides. Changes include a new test case validating the fix, a refactoring of the getResolvedTargetEntry function to improve override lookup logic, and a changeset entry documenting the patch version bump.

Changes

Cohort / File(s) Change Summary
Changeset
.changeset/proud-ads-poke.md
Added patch version bump entry for @ts-safeql/generate documenting a fix for incorrect custom type inference with custom column overrides.
Test Addition
packages/generate/src/generate-insert.test.ts
Added new test case "INSERT with type override in conjunction with unrelated column override should use custom type" validating that custom type overrides are applied correctly alongside column overrides.
Core Logic Refactor
packages/generate/src/generate.ts
Refactored getResolvedTargetEntry to use direct optional-chained lookups for column and type overrides instead of nested fmap blocks, improving control flow short-circuiting and ensuring correct override resolution order.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • packages/generate/src/generate.ts: The refactoring of override lookup logic requires careful verification that the new optional-chaining approach maintains correctness and doesn't alter the precedence of column overrides versus type overrides. The use of satisfies ResolvedTarget assertions should be validated.
  • packages/generate/src/generate-insert.test.ts: The new test case should be verified to ensure it accurately captures the bug scenario and that the assertions properly validate the fix.

Possibly related PRs

Poem

🐰 A bunny hops through override lanes,
Where columns dance and types remain,
Custom inference finds its way,
Through guarded checks that save the day!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing the priority of type overrides over column overrides, which directly corresponds to the bug fix implemented in the changeset and the refactored logic in generate.ts.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Newbie012 Newbie012 disabled auto-merge November 13, 2025 22:56
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/generate/src/generate.ts (1)

496-506: Remove redundant dead code from the refactor.

Lines 496-506 duplicate the type override logic already implemented at lines 490-494. This code is unreachable because:

  1. Line 492 already checks if typeOverride !== undefined and returns
  2. Line 496 checks params.context.overrides?.types === undefined, but this was already implicitly checked at line 490
  3. Line 500 performs the same lookup as line 490

This leftover code should be removed to eliminate confusion and maintain clarity.

Apply this diff to remove the redundant code:

   if (typeOverride !== undefined) {
     return { kind: "type", value: typeOverride.value, type: pgType.name } satisfies ResolvedTarget;
   }
-
-  if (params.context.overrides?.types === undefined || pgType === undefined) {
-    return undefined;
-  }
-
-  const override = params.context.overrides.types.get(pgType.name);
-
-  return fmap(
-    override,
-    ({ value }): ResolvedTarget => ({ kind: "type", value, type: pgType.name }),
-  );
+
+  return undefined;
 })();
🧹 Nitpick comments (1)
.changeset/proud-ads-poke.md (1)

1-5: Optional: Consider minor style improvements.

The static analysis tool suggests two optional style improvements:

  • "fixed" could be capitalized to "Fixed" for more formal wording
  • "in conjunction with" could be simplified to "with" for brevity

These are minor style preferences and the current wording is acceptable.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d1a7dc and 3bf5693.

📒 Files selected for processing (3)
  • .changeset/proud-ads-poke.md (1 hunks)
  • packages/generate/src/generate-insert.test.ts (1 hunks)
  • packages/generate/src/generate.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/proud-ads-poke.md

[style] ~4-~4: Consider using a different verb for a more formal wording.
Context: --- "@ts-safeql/generate": patch --- fixed an issue where custom type was inferred...

(FIX_RESOLVE)


[style] ~5-~5: ‘in conjunction with’ might be wordy. Consider a shorter alternative.
Context: ...re custom type was inferred incorrectly in conjunction with custom columns

(EN_WORDINESS_PREMIUM_IN_CONJUNCTION_WITH)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: check (16)
  • GitHub Check: check (17)
🔇 Additional comments (1)
packages/generate/src/generate-insert.test.ts (1)

476-495: LGTM! Test case effectively validates the fix.

This test case correctly validates that type overrides work properly when unrelated column overrides are configured. The test setup clearly demonstrates the bug scenario: a column override for tbl2.col should not prevent a type override for timestamptz from being applied to tbl.col.

@Newbie012 Newbie012 merged commit e020435 into main Nov 13, 2025
5 checks passed
@Newbie012 Newbie012 deleted the fix/custom-type-override-priority branch November 13, 2025 23:03
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