Skip to content

Commit a3c8c55

Browse files
authored
orm: deprecate global tenant filter APIs, deadline 2027-06-08 (#27389)
* orm: deprecate global tenant filter APIs, deadline 2027-06-08 The old global tenant filter mechanism (configure_tenant_filter, set_current_tenant_id, with_tenant, without_tenant_filter, etc.) is replaced by the per-instance DataScope / orm.DB pattern. Add @[deprecated] and @[deprecated_after] attributes to all 10 public items so users get a notice directing them to the new API. See: PR #27324 (DataScope support) * orm: remove deprecation from apply_tenant_filter (still used by DB backends) apply_tenant_filter is an internal helper called by the sqlite, mysql, and pg ORM backends in their select/update/delete paths. Marking it @[deprecated] would produce notices in every ORM-backed build and become a hard error after the grace period, breaking the backends. Keeps the 9 user-facing APIs deprecated as-is. * orm: deprecate apply_tenant_filter (covers remaining global-tenant public API point) * orm: remove deprecation from apply_tenant_filter (still used by DB backends) The apply_tenant_filter function is internal plumbing still used by db/sqlite, db/pg, and db/mysql backends. Deprecating it with -W in CI causes every tool that imports db/sqlite or any .vv test that imports it to fail. Keeps the other 9 deprecation markers (TenantFilterConfig, configure_tenant_filter, set_tenant_filter_enabled, set_current_tenant_id, clear_current_tenant_id, with_tenant, with_tenant_value, without_tenant_filter, without_tenant_filter_value). Fixes all 19 CI failures in PR #27389.
1 parent b0cf6a5 commit a3c8c55

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

vlib/orm/orm.v

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ struct TenantFilterScopeState {
298298
current_tenant Primitive
299299
}
300300

301+
@[deprecated: 'use `orm.DataScope` and `orm.new_db()` for per-instance request-level filtering']
302+
@[deprecated_after: '2027-06-08']
301303
pub struct TenantFilterConfig {
302304
pub:
303305
enabled bool = true
@@ -343,17 +345,23 @@ mut:
343345
}
344346

345347
// configure_tenant_filter configures the global ORM tenant filter behavior.
348+
@[deprecated: 'use `orm.DataScope` and `orm.new_db()` for per-instance request-level filtering']
349+
@[deprecated_after: '2027-06-08']
346350
pub fn configure_tenant_filter(config TenantFilterConfig) {
347351
tenant_filter_state.enabled = config.enabled
348352
tenant_filter_state.field_name = normalize_tenant_filter_field_name(config.field_name)
349353
}
350354

351355
// set_tenant_filter_enabled enables or disables global tenant filtering.
356+
@[deprecated: 'use `orm.DataScope` and `orm.new_db()` for per-instance request-level filtering']
357+
@[deprecated_after: '2027-06-08']
352358
pub fn set_tenant_filter_enabled(enabled bool) {
353359
tenant_filter_state.enabled = enabled
354360
}
355361

356362
// set_current_tenant_id sets the current tenant id used by global tenant filtering.
363+
@[deprecated: 'use `orm.DataScope` and `orm.new_db()` for per-instance request-level filtering']
364+
@[deprecated_after: '2027-06-08']
357365
pub fn set_current_tenant_id(tenant_id Primitive) {
358366
if tenant_id is Null {
359367
clear_current_tenant_id()
@@ -364,12 +372,16 @@ pub fn set_current_tenant_id(tenant_id Primitive) {
364372
}
365373

366374
// clear_current_tenant_id clears the current tenant id used by global tenant filtering.
375+
@[deprecated: 'use `orm.DataScope` and `orm.new_db()` for per-instance request-level filtering']
376+
@[deprecated_after: '2027-06-08']
367377
pub fn clear_current_tenant_id() {
368378
tenant_filter_state.has_current_tenant = false
369379
tenant_filter_state.current_tenant = null_primitive
370380
}
371381

372382
// with_tenant executes `callback` with a temporary tenant id and enabled tenant filtering.
383+
@[deprecated: 'use `orm.DataScope` and `orm.new_db()` for per-instance request-level filtering']
384+
@[deprecated_after: '2027-06-08']
373385
pub fn with_tenant[T](tenant_id Primitive, callback fn () !T) !T {
374386
saved := tenant_filter_scope_snapshot()
375387
tenant_filter_state.enabled = true
@@ -382,6 +394,8 @@ pub fn with_tenant[T](tenant_id Primitive, callback fn () !T) !T {
382394
}
383395

384396
// with_tenant_value executes `callback` with a temporary tenant id and enabled tenant filtering.
397+
@[deprecated: 'use `orm.DataScope` and `orm.new_db()` for per-instance request-level filtering']
398+
@[deprecated_after: '2027-06-08']
385399
pub fn with_tenant_value[T](tenant_id Primitive, callback fn () T) T {
386400
saved := tenant_filter_scope_snapshot()
387401
tenant_filter_state.enabled = true
@@ -394,6 +408,8 @@ pub fn with_tenant_value[T](tenant_id Primitive, callback fn () T) T {
394408
}
395409

396410
// without_tenant_filter executes `callback` with tenant filtering temporarily disabled.
411+
@[deprecated: 'use `orm.DB.unscoped()` for per-instance scope bypass']
412+
@[deprecated_after: '2027-06-08']
397413
pub fn without_tenant_filter[T](callback fn () !T) !T {
398414
saved := tenant_filter_scope_snapshot()
399415
tenant_filter_state.enabled = false
@@ -404,6 +420,8 @@ pub fn without_tenant_filter[T](callback fn () !T) !T {
404420
}
405421

406422
// without_tenant_filter_value executes `callback` with tenant filtering temporarily disabled.
423+
@[deprecated: 'use `orm.DB.unscoped()` for per-instance scope bypass']
424+
@[deprecated_after: '2027-06-08']
407425
pub fn without_tenant_filter_value[T](callback fn () T) T {
408426
saved := tenant_filter_scope_snapshot()
409427
tenant_filter_state.enabled = false

0 commit comments

Comments
 (0)