Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dsenalik
Copy link
Contributor

@dsenalik dsenalik commented Aug 27, 2024

Bug Fix

Closes #1920

Depends on #1921 (Merged)

Tripal Version: 4.x

Description

When editing an entity, the "Remove" button will remove a linked entity (e.g. remove analysis from project) in the Drupal table, but does not delete it from the underlying chado linker table. If instead it is changed to -- Select -- then it is removed from both the Drupal and Chado tables. This is because the "Remove" button removes the item from the form state so then Chado storage doesn't know it existed and doesn't know to delete it in Chado.

To resolve this problem, I am storing a few values in the form state on the very first creation of the form,
and then in the massageFormValues() function, we can check for records that were there when the form was first built, but have been eliminated since. If that is the case, then put a reference in the $values array which will inform chado storage to delete the record in chado.

This problem will exist only for fields which support cardinality greater than one. Fields that need the fix:

  • ChadoAnalysisWidgetDefault
  • ChadoArrayDesignWidgetDefault
  • ChadoAssayWidgetDefault
  • ChadoBiomaterialWidgetDefault
  • ChadoContactWidgetDefault
  • ChadoFeatureMapWidgetDefault
  • ChadoFeatureWidgetDefault
  • ChadoOrganismWidgetDefault
  • ChadoProjectWidgetDefault
  • ChadoProtocolWidgetDefault
  • ChadoPubWidgetDefault
  • ChadoStockWidgetDefault
  • ChadoStudyWidgetDefault

These will probably be different

  • ChadoDbxrefWidgetDefault
  • ChadoPropertySelectWidgetDefault
  • ChadoPropertyStringWidgetDefault
  • ChadoPropertyWidgetDefault
  • ChadoSynonymWidgetDefault

Changes not needed because cardinality is always 1

  • ChadoAdditionalTypeWidgetDefault

Testing?

(We need PR #1921 merged into this branch to test) merged

  1. Build a docker on the 4.x branch (to test update hook)
  2. Import Genetic and Genomic type collections and run the job drush trp-run-jobs --username=drupaladmin --root=/var/www/drupal/web
  3. switch to this branch git checkout tv4g1-issue1920-fix-remove-button
  4. Run update hook drush updatedb
>  [notice] Update started: tripal_chado_update_10406
>  [notice] Update completed: tripal_chado_update_10406
>  [notice] Message: Updating properties for Drupal table "tripal_entity__qtl_synonym", field  
> "qtl_synonym"
> 
>  [notice] Message: Updating properties for Drupal table  
> "tripal_entity__sequence_variant_synonym", field "sequence_variant_synonym"
> 
>  [notice] Message: Updating properties for Drupal table "tripal_entity__genetic_marker_synonym",  
> field "genetic_marker_synonym"
> 
>  [notice] Message: Updating properties for Drupal table  
> "tripal_entity__phenotypic_marker_synonym", field "phenotypic_marker_synonym"
> 
>  [notice] Message: Updating properties for Drupal table "tripal_entity__gene_synonym", field  
> "gene_synonym"
> 
>  [notice] Message: Updating properties for Drupal table "tripal_entity__mrna_synonym", field  
> "mrna_synonym"
> 
>  [notice] Message: Updating properties for Drupal table "tripal_entity__dna_library_synonym",  
> field "dna_library_synonym"
> 
>  [notice] Message: Updated 7 properties
> 
 [success] Finished performing updates.
  1. Create three contacts

  2. Create an organism

  3. Create a "Genetic Marker", and a) link all of the contacts, b) add some "Database Reference Annotations", c) add some synonyms, and save.
    1958_1

  4. Edit the Genetic Marker you created. Click the "Remove" button for one of the contacts, select "-- Select --" for another, then save.
    1958_2

  5. Contacts deleted using either of these methods should no longer appear on the entity.
    1958_3

  6. The two contacts should also be removed from the project_contact table and only one should remain - This is what was not happening before.

sitedb=> SELECT * FROM chado.feature_contact;
 feature_contact_id | feature_id | contact_id 
--------------------+------------+------------
                  7 |          1 |          4
(1 row)
  1. Edit again and do the same for synonyms, click "Remove" on one, empty the synonym box for another and save. Check the feature_synonym table.
  2. And likewise for the "Database Reference Annotations". Check the feature_dbxref table.
  3. To test properties, import a gff3 file, for example issue1824.gff3.txt
  4. Add new fields to "Gene"
  5. publish Gene
  6. Test removing some properties, you can examine with
    select * from featureprop FP left join cvterm T on FP.type_id=T.cvterm_id where FP.feature_id = (select feature_id from feature where name='PAU8');

@dsenalik dsenalik added Group 1 - Tripal Content Types | Terms | Fields Any issue relating to Tripal Content including types, terms, and fields. Group 2 - Data Storage | Tripal DBX | Chado Any issue relating to biological data storage, Tripal DBX and Chado integration, Materialized Views labels Aug 27, 2024
@dsenalik dsenalik marked this pull request as ready for review September 3, 2024 19:08
@dsenalik
Copy link
Contributor Author

dsenalik commented Sep 5, 2024

Commit dfa92b5 changes the internal identifier I was using from the field cv term to the field machine name. The latter is guaranteed to be unique, the former likely is, but issue #1932 is there because it is not currently enforced.

Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

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

✅ Code looks good. There is an assumption that there will be a record_id and a field_name element in the widget but I just documented it.
✅ Manual testing was successful. I tested the following situations:

  • deleted the last/only linker record
  • deleted by emptying the element
  • deleted by clicking the remove button
  • removed multiple entries in different fields in the same save
  • removed an entry with the remove button and then added one in the same page load
  • created multiple property fields with the same values and removed some values from each field but not the same ones to ensure there was no cross over. Checked where the value was the same and checked delta-wise as well.
  • checked on genetic marker and study
  • checked multiple different fields
  • confirmed after each save that the database underneath matched my expectations
  • confirmed nothing removed came back after publish

@dsenalik dsenalik merged commit d40840e into 4.x Sep 10, 2024
14 checks passed
@dsenalik dsenalik deleted the tv4g1-issue1920-fix-remove-button branch September 10, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Group 1 - Tripal Content Types | Terms | Fields Any issue relating to Tripal Content including types, terms, and fields. Group 2 - Data Storage | Tripal DBX | Chado Any issue relating to biological data storage, Tripal DBX and Chado integration, Materialized Views

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The "Remove" button on an entity edit does not remove a linked record from Chado

2 participants