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

Failure to destroy dependent CPK record causes a TypeError #600

Open
rockorequin opened this issue Jul 6, 2023 · 1 comment
Open

Failure to destroy dependent CPK record causes a TypeError #600

rockorequin opened this issue Jul 6, 2023 · 1 comment

Comments

@rockorequin
Copy link

I'm using Rails 7.0.6 and CPK 14.0.6 and have an ActiveRecord with a has_many association on a CPK ActiveRecord. The has_many is defined with dependent: :destroy, and when I attempt to destroy the parent ActiveRecord, one of the has_many CPK records fails to destroy. This causes Rails 7 to raise a TypeError.

The cause of the TypeError is in ~/.rvm/gems/ruby-3.2.0/gems/activerecord-7.0.6/lib/active_record/persistence.rb#_raise_record_not_destroyed():

key = self.class.primary_key
raise @_association_destroy_exception || RecordNotDestroyed.new("Failed to destroy #{self.class} with #{key}=#{send(key)}", self)

The TypeError is caused in the RecordNotDestroyed.new call because key is the CPK array of keys, so the send(key) call complains that key is not a symbol nor a string.

(I don't see why the Rails 7 code doesn't just call self.id, because this works, of course.)

@cfis
Copy link
Contributor

cfis commented Jul 15, 2023

Interesting that the test cases don't catch this. Can you provide the Active Record definitions applicable to this bug? Does any test case look similar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants