logidze icon indicating copy to clipboard operation
logidze copied to clipboard

Bug: logidze_logger_after created incorrectly on --update

Open gabo-cs opened this issue 4 months ago • 2 comments

ERROR (on db:rollback):

-- drop_function(:logidze_logger_after, {version: 5})
bin/rails aborted!
StandardError: An error has occurred, this and all later migrations canceled: (StandardError)

wrong number of arguments (given 2, expected 1)

Caused by:
ArgumentError: wrong number of arguments (given 2, expected 1) (ArgumentError)

Tasks: TOP => db:rollback

CONTEXT:

I ran rails generate logidze:install --update, and it generated the following migration (yes, including the extra whitespaces):

class LogidzeUpdate141 < ActiveRecord::Migration[7.2]
  def change






    reversible do |dir|
      dir.up do
        create_function :logidze_logger, version: 5
      end

      dir.down do
        create_function :logidze_logger, version: 2
      end
    end


    create_function :logidze_logger_after, version: 5





  end
end

Issues observed

  1. Rollback fails because drop_function(:logidze_logger_after, { version: 5 }) is invoked with two arguments, but looks like the adapter expects a single argument. Removing version: 5 allows rollback to succeed, but not sure if that's the intended behavior.
  2. Questionable generation of logidze_logger_after: the logidze_logger_after function appears to be generated even without passing an "after-trigger" flag. Is this intended for --update?
  3. Excessive whitespace: the generated migration includes multiple unnecessary blank lines.

gabo-cs avatar Aug 19 '25 16:08 gabo-cs

FWIW, I ran bundle update logidze before so gem was up to date.

gabo-cs avatar Aug 19 '25 20:08 gabo-cs

the logidze_logger_after function appears to be generated even without passing an "after-trigger" flag. Is this intended for --update?

Yes. We generate all the functions on install/update, so you can enable any feature later.

because drop_function(:logidze_logger_after, { version: 5 }) is invoked with two arguments

That looks like an fx bug; create_function is supposed to be invertible. Do you use the latest version of fx?

the generated migration includes multiple unnecessary blank lines.

I know 😁 Currently, we assume that you run RuboCop/Standard after generation (you're still likely to do so even without blank lines).

palkan avatar Oct 08 '25 13:10 palkan