Skip to content

Ruby 3.3 SyntaxError in each_tenant_parallel due to anonymous block forwarding (&) inside nested block #339

@leogar07

Description

@leogar07

Hi everyone,
we’re encountering a SyntaxError on Ruby 3.3.x when running rake tasks (e.g. rails db:migrate) with ros-apartment 3.4.1.

Environment
ros-apartment: 3.4.1
Ruby: 3.3.0
Rails: 7.0.3 (also reproducible independently of Rails)

Error
Running either rails db:migrate or a plain Ruby syntax check fails:
bundle exec ruby -c lib/apartment/tasks/task_helper.rb
Gives this error
anonymous block parameter is also used within block (SyntaxError)

Problematic code
In lib/apartment/tasks/task_helper.rb:
def each_tenant_parallel(&) with_advisory_locks_disabled do case resolve_parallel_strategy when :processes each_tenant_in_processes(&) else each_tenant_in_threads(&) end end end

Ruby 3.3 raises a SyntaxError when an anonymous block parameter (&) is referenced inside another block.

Expected behavior
ros-apartment rake tasks should run correctly on Ruby 3.3, as Ruby 3.3 is officially released and widely adopted.

Suggested fix (syntax-only, no behavior change)
Rename the anonymous block parameter to an explicit one:
def each_tenant_parallel(&block) with_advisory_locks_disabled do case resolve_parallel_strategy when :processes each_tenant_in_processes(&block) else each_tenant_in_threads(&block) end end end

This change fixes the SyntaxError and preserves existing behavior.

Impact

Breaks db:migrate and other rake tasks on Ruby 3.3+

Affects production systems that rely on Apartment-based multitenancy

Not detectable until rake tasks are executed

Happy to submit a PR if you’d like
Thanks for maintaining the gem!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions