fix: let read-only consumers build the provider registry without writing#791
Conversation
|
Warning Review limit reached
Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a ChangesRead-only registry build support
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ProviderRegistry
participant Database
Caller->>ProviderRegistry: build_from_config(config, db, register=False)
ProviderRegistry->>ProviderRegistry: import/configure providers
alt register is True
ProviderRegistry->>Database: db.session.begin()
ProviderRegistry->>Database: upsert provider/diagnostic rows
else register is False
ProviderRegistry-->>Caller: skip database write
end
ProviderRegistry-->>Caller: return ProviderRegistry instance
Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
`ProviderRegistry.build_from_config` unconditionally upserts provider and diagnostic rows, which is the only step that writes to the database. This crashed API startup when the database was opened read-only, since registration is already performed by `ref providers setup` and the workers. Add a `register` argument (default `True`, preserving existing behaviour) so read-only consumers such as the API can hydrate the registry with `register=False` and serve a database mounted read-only. Relates to Climate-REF/ref-app#31.
3628226 to
cd9e80d
Compare
Summary
ProviderRegistry.build_from_configunconditionally upserts provider and diagnostic rows via_register_provider, which is the only step in that method that writes to the database. That makes it impossible for a read-only consumer — notably theref-appAPI serving a database mounted read-only — to build the registry: startup crashes withattempt to write a readonly databaseeven though the rows it needs are already registered byref providers setupand the workers.This adds a
registerargument tobuild_from_config(defaultTrue, so every existing caller is unchanged). Read-only consumers passregister=Falseto hydrate the registry from imported providers without touching the database.Changes
ProviderRegistry.build_from_configgainsregister: bool = True; the_register_providerwrite loop is skipped when it isFalse.register=Falsepath, plus aTestProviderRegistryReadOnlyintegration test that migrates and registers a real database, reopens it read-only, and asserts thatregister=Falsebuilds with no write whileregister=TrueraisesOperationalError(the exact crash this fixes).Context
This is the
climate-refhalf of the fix for Climate-REF/ref-app#31; theref-appAPI is updated separately to passregister=Falseon its read-only path.Summary by CodeRabbit
New Features
Bug Fixes