activerecord-multi-tenant icon indicating copy to clipboard operation
activerecord-multi-tenant copied to clipboard

Incompatible with Rails 7.2

Open jerometremblay opened this issue 1 year ago • 2 comments

I had activerecord-multi-tenant referenced in my Gemfile but did not actually use it.

It broke when I updated my application to Rails 7.2.

Removing the gem fixed my application. So there must be some problem with the gem with this latest Rails version.

jerometremblay avatar Aug 20 '24 15:08 jerometremblay

Running into same issue, are there any plans for keeping this gem updated. The last release was a year ago.

kapso avatar Sep 02 '24 21:09 kapso

I found out additional issue in Rails 7.2 with counter_cache where this gem overrides the update_all method in https://github.com/citusdata/activerecord-multi-tenant/pull/223 which then calls

UPDATE posts SET comments_count = NULL WHERE ...

instead of

UPDATE posts SET comments_count = COALESCE(comments_count, 0) + $1 WHERE ...

at least in Rspecs we could observe this behavior. This is because the Arel::Node::Addition object is being type-casted by the Integer class (in sanitize_sql_for_assignment method) and since it is an object and not a number, it is sanitized to NULL instead of the valid SQL syntax.

I addressed it in this comment https://github.com/citusdata/activerecord-multi-tenant/pull/223/files#r1743665204. Rails distinguishes whether the updates object is a Hash and they have different logic on how to evaluate it in update_all.

I'm not sure if this can be somehow modified too.

Laykou avatar Sep 05 '24 08:09 Laykou