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

Refactors transaction step for saving admin data #889

Merged
merged 7 commits into from
Jul 16, 2024

Conversation

afred
Copy link
Contributor

@afred afred commented Jun 6, 2024

By default, multi-valued input fields display an additional set of input fields that are blank. These get submitted by the form and are usually discarded, but because we are treating Sony Ci ID field special, it was erroneously saving additional blank values for Sony Ci ID, which was resulting in multiple players of the same media dislaying on AAPB when the record was published.

Multiple Sony Ci IDs are allowed in cases of mult-part Assets. They are stored as a serialized JSON array in the AdminData.sonyci_id field, which is related to Asset reords via a global ID field on AdminData.gid. And the global ID fields was used instead of a normal foreign key because the AssetResource used to be just Asset, and stored in Fedora, not the database, and a global ID was the closest thing to a foreign key across 2 persistence layers that we could think of :)

Fixes #882.

By default, multi-valued input fields display an additional set of input fields that are blank.
These get submitted by the form and are usually discarded, but because we are treating Sony Ci
ID field special, it was erroneously saving additional blank values for Sony Ci ID, which was
resulting in multiple players of the same media dislaying on AAPB when the record was published.

Multiple Sony Ci IDs are allowed in cases of mult-part Assets. They are stored as a serialized JSON
array in the AdminData.sonyci_id field, which is related to Asset reords via a global ID field on
AdminData.gid. And the global ID fields was used instead of a normal foreign key because the
AssetResource used to be just Asset, and stored in Fedora, not the database, and a global ID was
the closest thing to a foreign key across 2 persistence layers that we could think of :)

Fixes #882.
@afred
Copy link
Contributor Author

afred commented Jun 6, 2024

@bkiahstroud and/or @orangewolf could I get an extra set of 👁️ on the logic here? This is some consequential code as it handles not only our Asset relations to Sony Ci media, but the Asset relation to the Bulkrax Importers and Batch Ingest Batches as well.

I think i tested all possibilities of adding/removing Sony Ci IDs, but did not do any kind of regression testing on persistence of bulkrax identifier or other admin data fields.

Copy link
Collaborator

@bkiahstroud bkiahstroud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few questions and suggestions. Also, it looks like some relevant specs are failing in CI

app/transactions/ams/steps/create_aapb_admin_data.rb Outdated Show resolved Hide resolved
app/transactions/ams/steps/create_aapb_admin_data.rb Outdated Show resolved Hide resolved
app/transactions/ams/steps/create_aapb_admin_data.rb Outdated Show resolved Hide resolved
afred and others added 4 commits June 11, 2024 15:49
Uses AdminData.attributes_for_updates as a filter to the change set fields.
Filters out blank sony ci ids so they don't get serialized.
Adds validation routine to AdminData for guarding against fields that cannot
  be deleted once set: bulkrax_importer_id and batch_ingest_batch_id.
  These IDs are foreign keys and if they accidentally get unset, we loase
  relational integrity, so need to make sure they are not accidentally
  getting unset via ingest, or updating Assets via UI, or anywhere else.
@afred
Copy link
Contributor Author

afred commented Jun 13, 2024

@bkiahstroud even more of a simplification...

  • Explicitly checks for sonyci_id field rather than using AdminData::SERIALIZED_FIELDS. This is an unnecessary abstraction that was put in place with the anticipation that we'd end up having more than one serialized field. It's been many years, and we have not, so I don't mind getting rid of that little bit of abstraction since that's the only place it's used. Furthermore, I think we'd be inclined to use regular JSON fields rather than serialized fields should an additional need arise.
  • Moves the logic for "you cannot delete values for some fields after they've been set" into validation method AdminData#validate_undeletable_fields, which is a more appropriate location since the logic should apply no matter where the model is being used for persistence. This eliminates the need for the should_empty_admin_data_value method and reduces logic complexity in set_admin_data_attributes
  • Removes unnecessary conversion of AdminData#attributes_for_update values from string, to symbol, back to string -- just keep them as strings, and we should be good.
  • Uses AdminData#attributes_for_update to slice out AdminData params from the AssetResourceForm rather than looping over it, allowing us to update the

@afred
Copy link
Contributor Author

afred commented Jun 13, 2024

Specs are passing for me locally, so idk what's up with the failures here. Can you replicate the failures locally?

@bkiahstroud
Copy link
Collaborator

Specs are passing for me locally, so idk what's up with the failures here. Can you replicate the failures locally?

I can, I get the same failures locally

@bkiahstroud
Copy link
Collaborator

@afred do you have changes locally that haven't been pushed up to this PR yet? For example, I don't see a new method named AdminData#validate_undeletable_fields that you referenced in this comment

…please squash when merging and remove this msg.

# The presence of the key with a "blank" value indicates we're intentionally emptying the value
change_set.fields.key?(key) && change_set.fields[key].blank?
admin_data.update!(admin_data_values)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#update! will persist the changes to the database, but I think the purpose of this method is just to set the values. The changes will be persisted by #save_aapb_admin_data. I recommend using #assign_attributes

@afred afred merged commit a435904 into develop Jul 16, 2024
6 checks passed
@afred afred deleted the 882-fix-dupe-sony-ci-id branch July 16, 2024 17:42
afred added a commit that referenced this pull request Aug 20, 2024
* Refactors transaction step for saving admin data

By default, multi-valued input fields display an additional set of input fields that are blank.
These get submitted by the form and are usually discarded, but because we are treating Sony Ci
ID field special, it was erroneously saving additional blank values for Sony Ci ID, which was
resulting in multiple players of the same media dislaying on AAPB when the record was published.

Multiple Sony Ci IDs are allowed in cases of mult-part Assets. They are stored as a serialized JSON
array in the AdminData.sonyci_id field, which is related to Asset reords via a global ID field on
AdminData.gid. And the global ID fields was used instead of a normal foreign key because the
AssetResource used to be just Asset, and stored in Fedora, not the database, and a global ID was
the closest thing to a foreign key across 2 persistence layers that we could think of :)

Fixes #882.

* Handles non-multiple, non-blank (default) case

Co-authored-by: Kiah Stroud <[email protected]>

* Add debug log for when nothing gets written

Co-authored-by: Kiah Stroud <[email protected]>

* Enumerates over SERIALIZED_FIELDS explicitly rather than duck typing

* Another refactor/simplification

Uses AdminData.attributes_for_updates as a filter to the change set fields.
Filters out blank sony ci ids so they don't get serialized.
Adds validation routine to AdminData for guarding against fields that cannot
  be deleted once set: bulkrax_importer_id and batch_ingest_batch_id.
  These IDs are foreign keys and if they accidentally get unset, we loase
  relational integrity, so need to make sure they are not accidentally
  getting unset via ingest, or updating Assets via UI, or anywhere else.

* adds missing code that was supposed to be part of the last commit 🤦, please squash when merging and remove this msg.

* Do not persist data in CreateAapbAdminData#set_admin_data_attributes

---------

Co-authored-by: Kiah Stroud <[email protected]>
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

Successfully merging this pull request may close these issues.

Extra Sony Ci ID field created on manual update
2 participants