Fix: read-only guard should block non-datastore resources#6
Conversation
Align the datastore write guard with CKAN's real `datastore_create` behavior: the guard fires when the resource's `url_type` is anything *other than* `"datastore"` (e.g. `upload` / link / external) — the cases where the datastore would clobber externally-managed data. Datastore-managed resources (those the datastore itself created with `url_type="datastore"`) are writable without `force`. The previous logic had the comparison inverted (`==` instead of `!=`), so the guard blocked writes to datastore-managed resources and silently allowed them on upload/link ones — the exact opposite of the intent. Also skip the guard when `url_type` is absent: there's no existing CKAN resource record to protect (e.g. the dict-form of `datastore_create` that materialises a fresh resource on the fly via `resource_create`). Tests / fixture: - FakeCKAN's seed resource now carries `url_type="datastore"` (mirrors a real datastore-managed resource), so the normal write tests aren't accidentally tripping the guard. - The read-only-guard tests across orchestration / create / upsert / delete are flipped to use `url_type="upload"` for the blocked case; new tests cover the datastore-managed and no-record (dict-create) skip cases.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe PR inverts the CKAN read-only guard logic to block writes to non-datastore resources unless ChangesCKAN Read-Only Guard Inversion
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Summary
Align the datastore write guard with CKAN's actual
datastore_createbehavior. The previous implementation had the comparison inverted — it was blocking writes to datastore-managed resources and silently allowing them on upload / link ones, the exact opposite of CKAN's intent.What the guard now does
url_typeforceforce=Truedatastore(managed by the datastore)upload/link/ any non-datastore valueValidation Error(read-only)datastore_create)AUTH_TYPE=jwt/anonymousThis matches CKAN's own check:
if res_dict.get('url_type') != 'datastore' and not data_dict.get('force'): raise.Code change
datastore/api/auth.py::ensure_resource_writableurl_type != "datastore"(the non-datastore case), not the other way around.url_typeis absent — the dict-form ofdatastore_createauthorises viapackage_idbefore the resource exists, so there's no record to protect.Tests / fixture
FakeCKANseed (balancing_auction_results_2025) now carriesurl_type="datastore"so the existing write tests aren't accidentally tripping the guard.tests/auth/test_orchestration.pyand the three endpoint test files (create/upsert/delete) are flipped: the "blocked without force" cases useurl_type="upload"; new cases cover the datastore-managed (writable) and no-record (dict-create) skip paths.Verification
pytest— 330 passing under the CI-equivalent env.ruff check— clean.Summary by CodeRabbit
Bug Fixes