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-542] Set stage #736

Merged
merged 5 commits into from Dec 12, 2023
Merged

[PY-542] Set stage #736

merged 5 commits into from Dec 12, 2023

Conversation

saurbhc
Copy link
Member

@saurbhc saurbhc commented Nov 30, 2023

Problem

Feature Request to set a 'Workflow Stage' to an Item/ItemQuery object.

Solution

Implement item.set_stage on both Item and ItemQuery level.

Notes:

  1. there are 2 arguments to set_stage:
    • stage_or_stage_id - you can pass either a Stage object OR stage_id str.
    • workflow_id is optional. If this is called via workflow object then set_stage will infer workflow_id from workflow meta_params. Otherwise, then workflow_id is required.
  2. Updated workflow meta object attribute items. It was calling the list_items API with workflow_id as QueryParam, removed it, and added workflow_id with value of self.id,dataset_ids in meta_params with value as the 1st dataset stage id (assuming a workflow only has 1 dataset stage).

Tested below cases:

  • Updating stage for Item(s) via workflow object
    workflow = client.team.workflows.where(dataset_name=dataset_name).collect_one()
    items = workflow.items.collect_all()
    workflow_id = str(workflow.id)
    for stage in workflow.stages:
        print(f"stage: {stage.name}")
        stage_id = str(stage.id)
        # dataset.items.set_stage(stage, workflow_id)  # works ✅
        for item in items:
            print(f"moving item {item.name} to stage {stage.name}")
            # item.set_stage(stage_id, workflow_id)  # works ✅
            item.set_stage(stage)  # works ✅
  • Updating stage for Item(s) via dataset object
    workflow = client.team.workflows.where(dataset_name=dataset_name).collect_one()
    workflow_id = str(workflow.id)
    dataset = client.team.datasets.where(name=dataset_name).collect_one()
    items = dataset.items.collect()
    for stage in workflow.stages:
        print(f"stage: {stage.name}")
        stage_id = str(stage.id)
        # workflow.items.set_stage(stage)  # works ✅
        for item in items:
            print(f"moving item {item.name} to stage {stage.name}")
            # item.set_stage(stage_id, workflow_id)  # works ✅
            item.set_stage(stage, workflow_id)  # works ✅

Changelog

Ability to Set Workflow Stage for Item/ItemQuery

@saurbhc saurbhc added the enhancement New feature or request label Nov 30, 2023
@saurbhc saurbhc self-assigned this Nov 30, 2023
Copy link

linear bot commented Nov 30, 2023

PY-542 Set stage

  • Set by id
  • Bypass stage object that was fetched before

WIP Acceptance Criteria

Item.set_stage(stage_id | stage, workflow_id)
ItemQuery.set_stage(stage_id | stage, workflow_id) # Batch operation

@saurbhc saurbhc marked this pull request as ready for review December 1, 2023 15:03
Copy link
Contributor

@Nathanjp91 Nathanjp91 left a comment

Choose a reason for hiding this comment

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

Looks good.

from darwin.future.exceptions import BadRequest
from darwin.future.meta.objects.base import MetaBase


class hasStage(Protocol):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be useful (in the future, not in this PR) to have like a protocols.py or interfaces.py file that imports all these objects (core only to avoid circular imports), that way we can build on these protocols

from darwin.future.exceptions import BadRequest
from darwin.future.meta.objects.item import Item


class hasStage(Protocol):
Copy link
Contributor

Choose a reason for hiding this comment

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

As above comment. Then we won't have to define these seperately. Single source of truth.

@saurbhc saurbhc merged commit d432b93 into master Dec 12, 2023
13 checks passed
@saurbhc saurbhc deleted the PY-542 branch December 12, 2023 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants