Skip to content

fix(datasource_active_record): skip anonymous models when building collections - #413

Merged
bexchauveto merged 2 commits into
mainfrom
feature/prd-1668-agent-ruby-a-rails-app-with-the-audit-trail-on-fails-at-boot
Oct 16, 2026
Merged

bexchauveto merged 2 commits into
mainfrom
feature/prd-1668-agent-ruby-a-rails-app-with-the-audit-trail-on-fails-at-boot

Conversation

@bexchauveto

@bexchauveto bexchauveto commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Fixes PRD-1668: a Rails app using the ActiveRecord datasource fails at boot when the audit trail is on.

What changes

  1. Before: Datasource#fetch_model called model.name.start_with? on every ActiveRecord::Base descendant, and the audit trail's anonymous Class.new(Sql::AuditLog) crashed it with undefined method 'start_with?' for nil. After: a model with no name is skipped.
  2. Before: no spec covered an anonymous model. After: datasource_spec.rb builds one on an existing table and checks that the datasource boots, leaves it out of the collections, and keeps the named ones.

The audit table stays out of the schema because its model is anonymous, and its abstract parents (AuditConnectionBase, AuditLog) were already skipped.

Decisions

  • PRD-1668: 1 architectural · all ticked

Squash message

fix(datasource_active_record): skip anonymous models when building collections

The ActiveRecord datasource called `name.start_with?` on every ActiveRecord::Base
descendant, so the audit trail's anonymous model made a Rails app with the audit trail on
crash at boot. A model without a name is now skipped: it can't name a collection, and the
audit table stays out of the schema.

Definition of Done

General

  • Write an explicit title for the Pull Request, following Conventional Commits specification
  • Test manually the implemented changes
  • Validate the code quality (indentation, syntax, style, simplicity, readability)

Security

  • Consider the security impact of the changes made

Note

Fix anonymous model crash in Datasource#fetch_model

Adds an early return in datasource.rb when an Active Record model has no name. Previously, calling start_with? on an anonymous model could abort datasource initialization. Named models keep the existing HABTM and collection-registration behavior.

Changes since #413 opened

  • Added a spec to verify ForestAdminAgent::AuditTrail::Store maintains an anonymous ActiveRecord model [5a99639]

Macroscope summarized c6383b5.

…llections

The audit trail binds its table through an anonymous ActiveRecord class, and the datasource
called `name.start_with?` on every ActiveRecord::Base descendant, so a Rails app with the audit
trail on crashed at boot on `nil`. A nameless model can't name a collection, so it is skipped,
which also keeps the audit table out of the schema.

Refs: PRD-1668

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Oct 16, 2026

Copy link
Copy Markdown

PRD-1668

@qltysh

qltysh Bot commented Oct 16, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (1)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
...record/lib/forest_admin_datasource_active_record/datasource.rb100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@bexchauveto
bexchauveto marked this pull request as ready for review October 16, 2026 14:13

@hercemer42 hercemer42 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Spec (PRD-1668): conforms.

end

def fetch_model(model)
# A collection is named after its model, so an anonymous one (such as the audit trail's) can't be one.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Applies to: packages/forest_admin_agent/lib/forest_admin_agent/audit_trail/store.rb:250 (not in this diff)
Claude Opus 5.5 (claude-opus-5-5): Preferential: if the audit store's model is ever given a name, Forest users see the audit table as a collection and no spec fails.

Code

store.rb:250 builds the audit model with Class.new(Sql::AuditLog), and that missing name is now all that keeps the audit table out of the schema.

A way out: assert store.send(:model).name is nil in store_spec.rb, next to the table_name check at line 272.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Claude Opus 5.5 (claude-opus-5-5): Added keeps its model anonymous to store_spec.rb, which fails if the store ever names its audit model.

5a99639

The ActiveRecord datasource now skips nameless models, and that is all that keeps the audit table
out of the schema, so a spec fails if the store ever names its model.

Refs: PRD-1668

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bexchauveto
bexchauveto merged commit c721960 into main Oct 16, 2026
33 checks passed
@bexchauveto
bexchauveto deleted the feature/prd-1668-agent-ruby-a-rails-app-with-the-audit-trail-on-fails-at-boot branch October 16, 2026 15:39
forest-bot added a commit that referenced this pull request Oct 16, 2026
## [1.46.1](v1.46.0...v1.46.1) (2026-10-16)

### Bug Fixes

* **datasource_active_record:** skip anonymous models when building collections ([#413](#413)) ([c721960](c721960))
@forest-bot

Copy link
Copy Markdown
Member

🎉 This PR is included in version 1.46.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants