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

[ENH] Add new query param for nodes that defaults to a prepopulated index #30

Merged
merged 28 commits into from
Nov 21, 2023

Conversation

alyssadai
Copy link
Contributor

@alyssadai alyssadai commented Nov 17, 2023

Changes proposed in this pull request:

Changes to existing code:

  • NB_NODES environment variable renamed to LOCAL_NB_NODES
  • .env file suggested to be named fed.env to differentiate from the node API .env file
  • Updated constraints for LOCAL_NB_NODES format in README
  • regex for matching nodes in LOCAL_NB_NODES updated to be whitespace-insensitive
  • Refactored out code to add trailing / to URLs into a util function, reused below

New code:

  • Added startup event to create an index of federation nodes that is a set of the public nodes from https://github.com/neurobagel/menu/blob/main/node_directory/neurobagel_public_nodes.json and the local nodes
    • If fetching public nodes fails, raise warning + just use the locally defined ones for federation
    • Existing /nodes/ endpoint updated to return values from federation index
  • Added new query parameter that accepts a list of node URLs
  • Validation added that queried node URL list is a subset of nodes known to the current (federation) API instance (i.e., a subset of the federation node index)
    • If not, throw an HTTPException
  • Added processing for queried node URL list to remove empty strings and duplicates

Checklist

  • PR has an interpretable title with a prefix ([ENH], [FIX], [REF], [TST], [CI], [MNT], [INF], [MODEL], [DOC]) (see https://neurobagel.org/contributing/pull_requests for more info)
  • PR links to GitHub issue with mention Closes #XXXX
  • Tests pass
  • Checks pass

For new features:

  • Tests have been added

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

@alyssadai alyssadai changed the title Add new query parameter that accepts a list of node URLs [ENH] Add new query parameter that accepts a list of node URLs Nov 17, 2023
@coveralls
Copy link
Collaborator

coveralls commented Nov 17, 2023

Pull Request Test Coverage Report for Build 6938616496

  • 148 of 148 (100.0%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+5.2%) to 98.127%

Totals Coverage Status
Change from base Build 6906927584: 5.2%
Covered Lines: 262
Relevant Lines: 267

💛 - Coveralls

@alyssadai alyssadai changed the title [ENH] Add new query parameter that accepts a list of node URLs [ENH] Add new query parameter for node URLs that defaults to a prepopulated index Nov 18, 2023
@alyssadai alyssadai changed the title [ENH] Add new query parameter for node URLs that defaults to a prepopulated index [ENH] Add new query param for nodes that defaults to a prepopulated index Nov 18, 2023
@alyssadai alyssadai marked this pull request as ready for review November 20, 2023 19:03
Copy link
Contributor

@surchs surchs left a comment

Choose a reason for hiding this comment

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

Thanks @alyssadai for this big PR. I left a couple of comments, mostly for clarity. Take a look.

Good to go otherwise: 🧑‍🍳

.gitignore Outdated Show resolved Hide resolved
@@ -89,7 +96,7 @@ async def get_terms(data_element_URI: str):
cross_node_results = []
params = {data_element_URI: data_element_URI}

for node_url in util.parse_nodes_as_dict(util.NEUROBAGEL_NODES).keys():
for node_url in util.FEDERATION_NODES:
Copy link
Contributor

Choose a reason for hiding this comment

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

does this mean that the get_terms request will always go out to all known nodes, regardless of any subselection the user might have made? in other words, wouldn't we also want to restrict this by

node_urls : list[str]
        List of Neurobagel nodes to send the query to.

as above in async def get?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've opened a separate issue for this

as I think this could benefit from some further discussion.

Right now, I think only the query tool uses this endpoint (/attributes/{data_element_URI}) to get all the instances of a given controlled term like nb:Assessment (across the known graphs) to populate the dropdown options for the UI. I imagine this would be separate from/before the user actually selects specific nodes in the app to send a query to - not sure if we want the query tool to have dynamically changing dropdown options as a result.

from typing import Optional, Union

from pydantic import BaseModel
from fastapi import Query
from pydantic import BaseModel, Field
Copy link
Contributor

Choose a reason for hiding this comment

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

isort? mind opening an issue to add this to the CI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isort is already included in the precommit hooks for this repo! 🙂

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

I think this is the expected import order following

  1. standard library imports
  2. related third party imports
  3. local application/library specific imports

app/api/utility.py Show resolved Hide resolved
app/api/utility.py Show resolved Hide resolved
tests/test_utility.py Show resolved Hide resolved
tests/test_utility.py Outdated Show resolved Hide resolved
tests/test_utility.py Show resolved Hide resolved
tests/test_utility.py Show resolved Hide resolved
tests/test_utility.py Outdated Show resolved Hide resolved
@alyssadai alyssadai merged commit dce8feb into main Nov 21, 2023
4 checks passed
@alyssadai alyssadai deleted the add-node-query-param branch November 21, 2023 04:37
@alyssadai alyssadai mentioned this pull request Nov 29, 2023
6 tasks
@surchs
Copy link
Contributor

surchs commented Apr 11, 2024

🚀 PR was released in v0.1.0 🚀

@surchs surchs added the released This issue/pull request has been released. label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
3 participants