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

Add multi-card primary descriptor #1368 #1452

Merged
merged 27 commits into from
Dec 21, 2023
Merged

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Nov 21, 2023

Description

Retires the primary descriptor from core arches that was limited to a single card. Creates a new primary descriptor that can draw from any card (using node aliases, which are unique), and wires it into the existing location for managing this (the function manager).

A migration deploys triggers to the tiles table that will calculate descriptors and writes to the resource instance table. (Another trigger captures changes to the function config itself and recalculates every resource.)

This migration was generated by django-pgtrigger, which abstracts away some of the boilerplate surrounding the trigger (e.g FOR EACH ROW etc), and allows for Django-y filters like Q() to add conditions on the trigger. This trigger is particularly complicated, but I can see this being helpful for simpler ones. Another benefit is managing the triggers in the application code and getting simple git diffs on the source.

Setup instructions

FUNCTION_LOCATIONS.append('arches_for_science.pkg.extensions.functions')
  • reinstall arches-for-science dependencies to get django-pgtrigger
  • reload the afs package in testing project (e.g. disco)
  • run migrations

Fixes #1368

@jacobtylerwalls jacobtylerwalls force-pushed the multi-card-primary-descriptor branch from c2921e9 to cbf1360 Compare November 21, 2023 21:38
@jacobtylerwalls jacobtylerwalls changed the title [WIP] Add multi-card primary descriptor [WIP] Add multi-card primary descriptor #1368 Nov 27, 2023
@jacobtylerwalls jacobtylerwalls force-pushed the multi-card-primary-descriptor branch from 7eb7812 to 308dc77 Compare November 28, 2023 23:05
@jacobtylerwalls jacobtylerwalls force-pushed the multi-card-primary-descriptor branch from 308dc77 to a09f04c Compare November 28, 2023 23:22
@jacobtylerwalls jacobtylerwalls force-pushed the multi-card-primary-descriptor branch from d8290ed to ee07138 Compare November 29, 2023 19:57
@jacobtylerwalls jacobtylerwalls changed the title [WIP] Add multi-card primary descriptor #1368 Add multi-card primary descriptor #1368 Nov 29, 2023
"string_template": "<Statement_content>"
"string_template": "<statement_content>"
Copy link
Member Author

Choose a reason for hiding this comment

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

These now need to be node aliases rather than node names. I could make the lookup case-insensitive, I suppose?

Copy link
Member

Choose a reason for hiding this comment

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

That would work in many cases, but a node alias can differ from the node name in other ways, generally because an alias must be unique to a graph and a name only must be unique to its siblings. So, I think it's good to be explicit about changing from names to aliases as you've done here.

arches_for_science/trigger_functions.py Show resolved Hide resolved
arches_for_science/trigger_functions.py Show resolved Hide resolved
arches_for_science/trigger_functions.py Show resolved Hide resolved
@jacobtylerwalls jacobtylerwalls marked this pull request as ready for review November 29, 2023 22:42
@jacobtylerwalls jacobtylerwalls force-pushed the multi-card-primary-descriptor branch from 0d800f3 to e5a0576 Compare December 1, 2023 15:35
README.md Show resolved Hide resolved
"string_template": "<Statement_content>"
"string_template": "<statement_content>"
Copy link
Member

Choose a reason for hiding this comment

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

That would work in many cases, but a node alias can differ from the node name in other ways, generally because an alias must be unique to a graph and a name only must be unique to its siblings. So, I think it's good to be explicit about changing from names to aliases as you've done here.

),
pgtrigger.migrations.AddTrigger(
model_name="functionxgraphproxy",
trigger=pgtrigger.compiler.Trigger(
Copy link
Member

Choose a reason for hiding this comment

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

I would expect the trigger to be removed on the reverse migration, but it persists. When you reverse migrate, are the pgtriggers dropped?

Copy link
Member Author

Choose a reason for hiding this comment

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

Works for me:

Reversing from 0008 to 0004:

root@d6b16aa0f3ba:/web_root/disco# python3 manage.py migrate arches_for_science 0004
System check identified some issues:

WARNINGS:
?: (urls.W005) URL namespace 'admin' isn't unique. You may not be able to reverse all URLs in this namespace
?: (urls.W005) URL namespace 'oauth2' isn't unique. You may not be able to reverse all URLs in this namespace
Operations to perform:
  Target specific migration: 0004_improve_primary_descriptor, from arches_for_science
Running migrations:
  Rendering model states... DONE
  Unapplying arches_for_science.0008_remove_tilemodelproxy_calculate_multicard_primary_descriptor_single_and_more... OK
  Unapplying arches_for_science.0007_update_primary_description_trigger_handle_static_value... OK
  Unapplying arches_for_science.0006_update_primary_description_trigger_null_handling... OK
  Unapplying arches_for_science.0005_deploy_triggers_for_primary_descriptor... OK
root@d6b16aa0f3ba:/web_root/disco# python3 manage.py dbshell
psql (14.9 (Ubuntu 14.9-1.pgdg22.04+1), server 14.5 (Debian 14.5-1.pgdg110+1))
Type "help" for help.

disco=# \dS tiles
...
Triggers:
    __arches_check_excess_tiles_trigger BEFORE INSERT ON tiles FOR EACH ROW EXECUTE FUNCTION __arches_check_excess_tiles_trigger_function()
    __arches_trg_update_spatial_attributes AFTER INSERT OR DELETE OR UPDATE ON tiles DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION __arches_trg_fnc_update_spatial_attributes()

I noticed that there was a missing migration on this branch from Friday, that might have been the issue.

@jacobtylerwalls jacobtylerwalls force-pushed the multi-card-primary-descriptor branch from 1bf4655 to 9fd24fa Compare December 12, 2023 22:25
@jacobtylerwalls
Copy link
Member Author

@chiatt FYI -- during release testing I just discovered that node aliases are nullable. So this hasn't really been tested against that (I would guess that which node we resolve <> to is probably undefined).

@chiatt
Copy link
Member

chiatt commented Dec 14, 2023

@chiatt FYI -- during release testing I just discovered that node aliases are nullable. So this hasn't really been tested against that (I would guess that which node we resolve <> to is probably undefined).

There must have been a reason for making them nullable when the alias was introduced. I don't recall what that would have been, but perhaps it should be changed - in 7.6 at least.

Copy link
Member

@chiatt chiatt left a comment

Choose a reason for hiding this comment

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

Looks great!

@chiatt chiatt merged commit f8de390 into dev/1.1.x Dec 21, 2023
1 check passed
@chiatt chiatt deleted the multi-card-primary-descriptor branch December 21, 2023 01:29
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.

Usability enhancement: Display provenance of samples and analysis areas in search and dropdowns
3 participants