Fix Rails edge compatibility (Kimi K3) - #421
Merged
Merged
Conversation
This was referenced Sep 7, 2026
Rails 8.2 reads column metadata in bulk through the private fetch_column_definitions API, resolving relations through the schema search path instead of casting names to regclass. This bypassed the column_definitions override that redirects temporal tables to the temporal schema, so metadata was read from the public view, which carries no column defaults nor NOT NULL constraints. As a result, the temporal view DDL never set the view column defaults and the INSTEAD OF INSERT trigger received NULL for omitted/defaulted columns, raising PG::NotNullViolation, and models lost their attribute defaults (GH #414). Override fetch_column_definitions with the same temporal schema redirection when the parent adapter implements it. Fixes #414.
amedeo
force-pushed
the
fix/414-by-k3
branch
from
September 7, 2026 13:14
07aa8e9 to
3b73057
Compare
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.
Problem
On Rails edge (8.2.0.alpha), the DDL and counter-cache specs fail with
PG::NotNullViolation: the temporal view'sINSTEAD OFtrigger receivesNULLfor omitted/defaulted columns (see #414).Root cause
Rails 8.2 refactored schema introspection:
columns(table)no longer callscolumn_definitions(table_name). It now uses a new private bulk API,fetch_column_definitions(tables), which resolves relations throughcurrent_schemas(false)(the schema search path) instead of casting names toregclass.ChronoModel redirects temporal tables to the
temporalschema by overridingcolumn_definitions— and that override is silently bypassed. Column metadata is then read from the public view, which carries no column defaults and noNOT NULLconstraints, instead of from the temporal table. Consequentlychrono_public_view_ddlnever executes itsALTER VIEW ... ALTER COLUMN ... SET DEFAULTstatements, so:INSTEAD OF INSERTtrigger receivesNULLfor omitted/defaulted columns →PG::NotNullViolationin the DDL specs;articles_countread asnilinstead of0in the counter-cache spec).Note that the
primary_key,indexesanddefault_sequence_nameoverrides are not affected: on edge they remain the public entry points and delegate to the bulk fetchers internally, under ChronoModel'son_schema(TEMPORAL_SCHEMA)wrapping.Fix
lib/chrono_model/adapter.rb— adds afetch_column_definitionsoverride next to the existingcolumn_definitionsoverride, feature-guarded withPostgreSQLAdapter.private_method_defined?(:fetch_column_definitions)(inert on Rails ≤ 8.1). It partitions chrono vs. plain tables and reads chrono tables insideon_schema("#{TEMPORAL_SCHEMA},#{schema_search_path}", recurse: :ignore), mirroring the existing override. Mixed bulk calls (e.g. schema cacheadd_allcallingcolumns(all_tables)) are handled correctly.The
on_schemaspec coupling to theschema_search_path=behavior change on PostgreSQL 18+ was resolved separately on master by #425 and #427, so this PR is now production-code only.Test results
Full suite run locally (Ruby 3.4) against this branch rebased on master, with per-gemfile regenerated dummy test apps:
On master without this patch, the Rails edge jobs fail with the 7 remaining root-cause examples (6 in
ddl_spec, 1 incounter_cache_race_spec); this branch fixes all of them.Fixes #414