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

descriptors update (ActiveRecord::RecordNotDestroyed) "Failed to destroy the record" #2713

Closed
LocoDelAssembly opened this issue Dec 7, 2021 · 4 comments
Assignees
Labels
bug An existing function is broken.

Comments

@LocoDelAssembly
Copy link
Contributor

An ActiveRecord::RecordNotDestroyed occurred in descriptors#update:

Failed to destroy the record
app/controllers/descriptors_controller.rb:62:in `block in update'


Github link:

https://github.com/SpeciesFileGroup/taxonworks/blob/6da13f6e5/app/controllers/descriptors_controller.rb#L62

I'm unsure what happens here. Does the frontend supply the complete desired database state (scoped to one descriptor) and not just what needs to be updated, created or deleted?

@proceps
Copy link
Contributor

proceps commented Dec 7, 2021

Not sure either, it looks like somebody tried to delete a descriptor on a sandbox. But that descriptor has several char_states and numerous obseravtion. It should not be deletable. May be just the error have to be handled more nicely?

@LocoDelAssembly
Copy link
Contributor Author

This was an update call to the model, but apparently the params carry an array of nested attributes and I guess ActiveRecord tries to delete those related records that are no longer present in the supplied array. I'm a bit worried that the frontend might have a bigger responsibility than in should and shouldn't manipulate relationships so directly?

Since this is a sandbox I'll assume it is safe to publish the params:

{
    "descriptor" => {
                               "name" => "Body form",
                         "short_name" => "Body form",
                        "description" => "{proportion between length and width}",
                       "default_unit" => nil,
                               "type" => "Descriptor::Qualitative",
                           "position" => 9874,
                   "description_name" => "Body form",
                           "key_name" => "Body form",
                             "weight" => nil,
               "gene_attribute_logic" => nil,
        "character_states_attributes" => [
            [0] {
                              "id" => 878,
                            "name" => "slender, length more than 5 times maximum width",
                "description_name" => "slender",
                        "key_name" => "slender",
                           "label" => "0",
                   "descriptor_id" => 923,
                        "position" => 1
            },
            [1] {
                              "id" => 1979,
                            "name" => "moderate, length between 2 to 4 times maximum width",
                "description_name" => "moderate or robust",
                        "key_name" => "moderate or robust",
                           "label" => "1",
                   "descriptor_id" => 923,
                        "position" => 2
            },
            [2] {
                              "id" => 3253,
                            "name" => "robust, lenght less than or equal to two times maximum width",
                "description_name" => nil,
                        "key_name" => nil,
                           "label" => "2",
                   "descriptor_id" => 923,
                        "position" => 3,
                        "_destroy" => true
            }
        ]
    },
    "controller" => "descriptors",
        "action" => "update",
            "id" => "923",
        "format" => "json"
}

Looking at this prettier representation of the params I see last one is marked to be destroyed (while at the same time all the fields values are also provided).

@mjy mjy added the bug An existing function is broken. label Dec 13, 2021
@mjy mjy closed this as completed in d1a4217 Dec 13, 2021
@LocoDelAssembly
Copy link
Contributor Author

Fix was for something else. Reopening.

@mjy
Copy link
Member

mjy commented Dec 14, 2021

Solved by catching raise, might be missing something in related models, particularly before/after, but nothing obvious hit. Apparently this is expected behaviour if you have dependent => destroy => despendent => destroy (restrict with error) chains.

@mjy mjy closed this as completed in 570854c Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing function is broken.
Projects
None yet
Development

No branches or pull requests

4 participants