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

[PY-407][PY-534][PY-404] Item + ItemQuery objects #715

Merged
merged 22 commits into from
Nov 13, 2023
Merged

[PY-407][PY-534][PY-404] Item + ItemQuery objects #715

merged 22 commits into from
Nov 13, 2023

Conversation

Nathanjp91
Copy link
Contributor

Problem

Item + ItemQuery doesn't exist, need to be added in so can manage and download these items. Also add in associated methods and features to objects that have Items as well as methods that items should have

Solution

Added in these objects

  • Item Meta now exists along with ItemQuery
  • delete() method on both item and itemquery that requests the item/s be deleted on the server
  • objects that interact with items have an items property that maps to a ItemQuery
  • Small changes to QueryString for easier typing

Changelog

Items now queryable with paginated support

Copy link

linear bot commented Nov 13, 2023

PY-407 Create ItemQuery object and relevant functions/filters

https://www.notion.so/v7labs/Item-Management-Functionality-Scoping-df5f846a135e46e1bf31c473afda32ee?pvs=4#16946909a4aa4929a43e4592ffd209a4

Create an ItemQuery object and functions and filters to work with items as needed.

item = team.items.get(id)
# - or -
item = team.item.where(query).first() # or .one() etc., depending on API

Note: Should plan to only support Advanced Filters

output += f"{k}={x}&"
else:
output += f"{k}={v}&"
return output[:-1] # remove trailing &

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This had to be changed and added to facilitate that a key can map to multiple values, eg dataset_id=0000&dataset_id=0001

@@ -75,7 +75,7 @@ def validate_fps(cls, values: dict) -> dict:
elif isinstance(value, (int, float)):
type = values.get("type")
if type == "image":
assert value == 0, "fps must be 0 for images"
assert value == 0 or value == 1.0, "fps must be '0' or '1.0' for images"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

turns out on our api, 1.0 also exists for items that are images. Found in dogfooding.


JSONType = Union[Dict[str, Any], List[Dict[str, Any]]] # type: ignore


class Implements_str(Protocol):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so this protocol should mean it'll work with anything that can be converted to a string, so things like ints, floats etc will work.


def __init__(self, value: Dict[str, str]) -> None:
def __init__(self, value: Mapping[str, list[Stringable] | Stringable]) -> None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mapping here is a more free-form Dict. As per the mypy docs, it's better to use the constructs like Mapping/Sequence as input parameters, and more concrete ones like dict/list as return types.

...


Stringable = Union[str, Implements_str]
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'm not entirely sure why this union has to exist, but I couldn't get the type system to properly work without it. One would expect implements_str to encompass str natively, but it doesn't.

@Nathanjp91 Nathanjp91 changed the title [PY-407] Item + ItemQuery objects [PY-407][PY-534][PY-404] Item + ItemQuery objects Nov 13, 2023
Copy link

linear bot commented Nov 13, 2023

PY-534 Change stage.item_ids to stage.items

Currently, WFStage has a member, item_ids which returns a list of the UUIDs of the stage items.

Change this to the actual stage objects, when possible.

Acceptance Criteria

WFStage has items member populated with item data structures, instead of a list of IDs

PY-404 Create delete method on item

https://www.notion.so/v7labs/Item-Management-Functionality-Scoping-df5f846a135e46e1bf31c473afda32ee?pvs=4#16946909a4aa4929a43e4592ffd209a4

items = team.items.where(query)

[item.delete() for item in items]

Both items and query should have their own delete. (This applies to all batch actions)

Copy link
Contributor

@owencjones owencjones left a comment

Choose a reason for hiding this comment

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

Some comments for consideration, but overall LGTM

payload = {
"filters": {
"dataset_ids": dataset_ids
"dataset_ids": [str(item) for item in dataset_ids]
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, so this accepts "all" as a possible input? That surprises me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all our endpoints do, although I have just removed that because I do think it's dangerous. Also it makes typing a bit of a nightmare anyway.

darwin/future/data_objects/item.py Outdated Show resolved Hide resolved
@@ -13,12 +11,23 @@ def test_querystring_happy_path() -> None:
assert str(query_string_2) == "?foo=bar&baz=qux"

query_string_3 = QueryString({})
assert str(query_string_3) == "?"
assert str(query_string_3) == ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, protocols do work much better for this eh.

@Nathanjp91 Nathanjp91 merged commit 0efb835 into master Nov 13, 2023
13 checks passed
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.

3 participants