Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete: :by_pk in a repository breaks with timestamps plugin #672

Open
gpaddis opened this issue Feb 28, 2022 · 0 comments
Open

delete: :by_pk in a repository breaks with timestamps plugin #672

gpaddis opened this issue Feb 28, 2022 · 0 comments

Comments

@gpaddis
Copy link

gpaddis commented Feb 28, 2022

Describe the bug

When the delete command is defined in a repository together with the timestamps plugin, I get the following error by deleting a record:

wrong number of arguments (given 1, expected 2+) (ArgumentError)

It might be linked to #475

To Reproduce

require 'bundler/inline'

gemfile(install: true) do
  source 'http://rubygems.org'

  gem 'rom'
  gem 'rom-sql'
  gem 'sqlite3'
end

class Users < ROM::Relation[:sql]
  schema(infer: true)
end

class UserRepository < ROM::Repository[:users]
  commands :create,
           update: :by_pk,
           delete: :by_pk,
           use: :timestamps,
           plugins_options: {
             timestamps: {
               timestamps: %i[created_at updated_at]
             }
           }
end

rom = ROM.container(:sql, 'sqlite::memory') do |conf|
  conf.default.create_table :users do
    primary_key :id
    column :name, String, null: false
    column :created_at, DateTime, null: false
    column :updated_at, DateTime, null: false
  end

  conf.register_relation(Users)
end

repo = UserRepository.new(rom)

user = repo.create(name: 'New User')
p user

p repo.delete(user.id)

# output:
# #<ROM::Struct::User id=1 name="New User" created_at=2022-02-28 07:25:30 +0100 updated_at=2022-02-28 07:25:30 +0100>
# /Users/gianpieroaddis/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rom-core-5.2.6/lib/rom/command.rb:475:in `apply_hooks': wrong number of arguments (given 1, expected 2+) (ArgumentError)
#         from /Users/gianpieroaddis/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rom-core-5.2.6/lib/rom/command.rb:277:in `call'
#         from /Users/gianpieroaddis/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rom-sql-3.5.0/lib/rom/sql/commands/error_wrapper.rb:18:in `call'
#         from /Users/gianpieroaddis/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rom-core-5.2.6/lib/rom/commands/composite.rb:19:in `call'
#         from /Users/gianpieroaddis/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rom-repository-5.2.2/lib/rom/repository/class_interface.rb:153:in `block (2 levels) in define_restricted_command_method'
#         from rom.rb:43:in `<main>'

Expected behavior

repo.delete(user.id) should only expect one argument.

My environment

ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin19]

@solnic solnic added this to the 6.0.0 milestone May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants