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

Skip to content

Conversation

@laceysanderson
Copy link
Member

Bug Fix

Issue #1939

Tripal Version: 4

Description

Many field properties do not have defaults set for when chado mapping is not present. This causes field addition to fail whenever the column doesn't exist in the chado mapping. Instead this PR add a default for all properties and then if chado mapping provides a more specific term, we use it.

Testing?

  1. Start a new Tripaldocker container
  2. Add a type_id to the project table so that we have a column without a chado mapping.
docker exec CONTAINERNAME drush sql:query "ALTER TABLE chado.project ADD COLUMN type_id bigint"
docker exec CONTAINERNAME drush sql:query "ALTER TABLE chado.project ADD FOREIGN KEY (type_id) REFERENCES chado.cvterm (cvterm_id) ON DELETE SET NULL;"
  1. Update the chado schema yaml to ensure Tripal knows about this field. This is needed due to the bug mentioned in issue Field Settings form is not aware of updates to the schema #1936. Apply the following patch to tripal_chado/chado_schema/chado_schema-1.3.yml.
diff --git a/tripal_chado/chado_schema/chado_schema-1.3.yml b/tripal_chado/chado_schema/chado_schema-1.3.yml
index 7f482d32f..a73cb9c9d 100644
--- a/tripal_chado/chado_schema/chado_schema-1.3.yml
+++ b/tripal_chado/chado_schema/chado_schema-1.3.yml
@@ -4898,6 +4898,13 @@ project:
     description:
       type: text
       not null: FALSE
+    type_id:
+      type: integer
+  foreign keys:
+    cvterm:
+      table: cvterm
+      columns:
+        type_id: cvterm_id
   unique keys:
     project_c1: name
   primary key: project_id
  1. Clear the cache using drush cr
  2. Now in the UI, go to Tripal > Page Structure > Project > Manage Fields in the administrative toolbar.
  3. Click on "Create a new field" and add a label of "type", select "Chado Fields", then "Chado Integer Field Type" and click Continue.
  4. Thanks to the changes in step 2/3 you now see a "type_id" in the "table column" drop down. Select it and set a term for the field such as "rdfs:type".
  5. On 4.x you will now see a WSOD and error message as indicated in the linked issue. On this branch the field will add without error.
  6. Now create a project page and confirm the page saves without error and that you can set the type_id :-)

@laceysanderson laceysanderson self-assigned this Jul 31, 2024
@laceysanderson laceysanderson added bug - confirmed For issues where a core developer has confirmed a bug exists. Group 1 - Tripal Content Types | Terms | Fields Any issue relating to Tripal Content including types, terms, and fields. labels Jul 31, 2024
@laceysanderson laceysanderson marked this pull request as ready for review July 31, 2024 20:37
Copy link
Contributor

@dsenalik dsenalik left a comment

Choose a reason for hiding this comment

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

That must have been a pain to add all those! But looks good.
Described test adding as a Chado Integer Field Type field worked as advertised.
Then I thought to try adding as a Chado Type Reference. When I go to create the project I see
The website encountered an unexpected error. Try again later.

TypeError: Drupal\tripal\TripalStorage\TripalStorageBase::addTypes(): Argument #2 ($types) must be of type array, null given, called in /var/www/drupal/web/modules/contrib/tripal/tripal/src/Entity/TripalEntity.php on line 425 in Drupal\tripal\TripalStorage\TripalStorageBase->addTypes() (line 115 of modules/contrib/tripal/tripal/src/TripalStorage/TripalStorageBase.php).

We are not getting anything from this in tripal/src/Entity/TripalEntity.php

        // Get the empty property values for this field item and the
        // property type objects.
        $prop_values = $item->tripalValuesTemplate($item->getFieldDefinition());
        $prop_types = get_class($item)::tripalTypes($item->getFieldDefinition());

Copy link
Contributor

@dsenalik dsenalik left a comment

Choose a reason for hiding this comment

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

The bug I found is now issue #1941
So there is nothing wrong with this PR

@laceysanderson
Copy link
Member Author

Thank you for the review @dsenalik! ❤️ Yes, it was tedious adding all of those 🤪 but the chado mapping UI helped to look them all up in the right format so it was better then it could have been!

@laceysanderson laceysanderson merged commit 85ca8c0 into 4.x Aug 1, 2024
@dsenalik dsenalik deleted the tv4g1-1939-setPropertyTermDefaults branch August 1, 2024 15:47
Comment on lines -219 to +221
$type_table = $storage_settings['type_table'] ?? '';
$type_column = $storage_settings['type_column'] ?? '';
$type_fkey = $storage_settings['type_fkey'] ?? '';
$type_table = $storage_settings['type_table'] ?: '';
$type_column = $storage_settings['type_column'] ?: '';
$type_fkey = $storage_settings['type_fkey'] ?: '';
Copy link
Contributor

@dsenalik dsenalik Aug 8, 2024

Choose a reason for hiding this comment

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

This should not have been changed and will be reverted by PR #1942
This change causes a warning that array key does not exist in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug - confirmed For issues where a core developer has confirmed a bug exists. Group 1 - Tripal Content Types | Terms | Fields Any issue relating to Tripal Content including types, terms, and fields.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Many field properties do not have defaults set for when chado mapping is not present.

2 participants