Skip to content

Fix Rails edge compatibility (Kimi K3) - #421

Merged
tagliala merged 1 commit into
masterfrom
fix/414-by-k3
Sep 7, 2026
Merged

tagliala merged 1 commit into
masterfrom
fix/414-by-k3

Conversation

@amedeo

@amedeo amedeo commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Problem

On Rails edge (8.2.0.alpha), the DDL and counter-cache specs fail with PG::NotNullViolation: the temporal view's INSTEAD OF trigger receives NULL for omitted/defaulted columns (see #414).

Root cause

Rails 8.2 refactored schema introspection: columns(table) no longer calls column_definitions(table_name). It now uses a new private bulk API, fetch_column_definitions(tables), which resolves relations through current_schemas(false) (the schema search path) instead of casting names to regclass.

ChronoModel redirects temporal tables to the temporal schema by overriding column_definitions — and that override is silently bypassed. Column metadata is then read from the public view, which carries no column defaults and no NOT NULL constraints, instead of from the temporal table. Consequently chrono_public_view_ddl never executes its ALTER VIEW ... ALTER COLUMN ... SET DEFAULT statements, so:

  • the INSTEAD OF INSERT trigger receives NULL for omitted/defaulted columns → PG::NotNullViolation in the DDL specs;
  • models lose their DB-level attribute defaults (e.g. articles_count read as nil instead of 0 in the counter-cache spec).

Note that the primary_key, indexes and default_sequence_name overrides are not affected: on edge they remain the public entry points and delegate to the bulk fetchers internally, under ChronoModel's on_schema(TEMPORAL_SCHEMA) wrapping.

Fix

lib/chrono_model/adapter.rb — adds a fetch_column_definitions override next to the existing column_definitions override, feature-guarded with PostgreSQLAdapter.private_method_defined?(:fetch_column_definitions) (inert on Rails ≤ 8.1). It partitions chrono vs. plain tables and reads chrono tables inside on_schema("#{TEMPORAL_SCHEMA},#{schema_search_path}", recurse: :ignore), mirroring the existing override. Mixed bulk calls (e.g. schema cache add_all calling columns(all_tables)) are handled correctly.

The on_schema spec coupling to the schema_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:

Configuration Result
rails_edge + PostgreSQL 18.6 ✅ 509 examples, 0 failures
rails_edge + PostgreSQL 16.11 ✅ 509 examples, 0 failures
rails_8.1 + PostgreSQL 18.6 ✅ 509 examples, 0 failures
rails_8.0 + PostgreSQL 18.6 ✅ 509 examples, 0 failures
rails_7.2 + PostgreSQL 18.6 ✅ 509 examples, 0 failures
rails_7.1 + PostgreSQL 18.6 ✅ 509 examples, 0 failures
rails_7.0 + PostgreSQL 18.6 ✅ 511 examples, 0 failures
RuboCop (87 files) ✅ no offenses

On master without this patch, the Rails edge jobs fail with the 7 remaining root-cause examples (6 in ddl_spec, 1 in counter_cache_race_spec); this branch fixes all of them.

Fixes #414

@amedeo
amedeo requested a review from tagliala September 6, 2026 19:57
@amedeo amedeo changed the title Fix Rails edge compatibility (fetch_column_definitions) Fix Rails edge compatibility (Kimi K3) 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.
@tagliala
tagliala merged commit b995754 into master Sep 7, 2026
31 checks passed
@tagliala
tagliala deleted the fix/414-by-k3 branch September 7, 2026 13: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.

ChronoModel does not work on Rails edge

2 participants