Update StateQuerying#effective_state to read column directly

What does this MR do and why?

Reads Namespace#effective_state from the state column instead of ancestor traversal, behind the namespace_state_propagation feature flag.

  • Flag ON → direct column/attribute read (state_name)
  • Flag OFF → search for inherited state from the closest ancestor.

This is the first step toward eliminating recursive state resolution. Future work will route archived? and deletion_scheduled? through effective_state.

References

How to set up and validate locally

  1. Run the following demo script in the rails console
flag = :namespace_state_propagation

original_flag_state = Feature.enabled?(flag)
original_log_level  = Rails.logger.level
Rails.logger.level  = Logger::ERROR # silence SQL and feature-flag warnings

begin
  ActiveRecord::Base.transaction do
    org    = Organizations::Organization.first
    suffix = SecureRandom.hex(4)

    root  = Group.create!(name: "sp-root-#{suffix}",  path: "sp-root-#{suffix}",  organization: org)
    child = Group.create!(name: "sp-child-#{suffix}", path: "sp-child-#{suffix}", organization: org, parent: root)

    root.update!(state: :archived)
    child.update!(state: :ancestor_inherited)
    child.reload

    puts "root state=#{root.state}  child state=#{child.state}  child traversal_ids=#{child.traversal_ids.inspect}"
    puts "-" * 70

    Feature.enable(flag)
    on = child.reload.effective_state
    puts "flag ON  -> child.effective_state = #{on.inspect}  (expected :ancestor_inherited — direct column read)"

    Feature.disable(flag)
    off = child.reload.effective_state
    puts "flag OFF -> child.effective_state = #{off.inspect}  (expected :archived — resolved from ancestor)"

    puts "-" * 70
    if on == :ancestor_inherited && off == :archived
      puts "RESULT: PASS — flag ON returns the direct state; flag OFF resolves the ancestor state."
    else
      puts "RESULT: FAIL — unexpected values (ON=#{on.inspect}, OFF=#{off.inspect})."
    end

    raise ActiveRecord::Rollback
  end
ensure
  original_flag_state ? Feature.enable(flag) : Feature.disable(flag)
  Rails.logger.level = original_log_level
end

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Shane Maglangit

Merge request reports

Loading