Skip to content

Deprecate workflow_target in ProcessSubscriptionTable and store_process_subscription() #986

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

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/architecture/application/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create_node_enrollment() -> StepList:
return (
begin
>> construct_node_enrollment_model
>> store_process_subscription(Target.CREATE)
>> store_process_subscription()
...
...
...
Expand Down Expand Up @@ -82,7 +82,7 @@ def construct_node_enrollment_model(
After that the the subscription is created and registered with the orchestrator:

```python
>> store_process_subscription(Target.CREATE)
>> store_process_subscription()
```

The subsequent steps are the actual logic being executed by the workflow. It's a best practice to have each step execute one discrete operation so in case a step fails it can be restarted. To wit if a step contained:
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/product_modelling/imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create_imported_node() -> StepList:
return (
begin
>> create_subscription
>> store_process_subscription(Target.CREATE)
>> store_process_subscription()
>> initialize_subscription
)
```
Expand Down
2 changes: 1 addition & 1 deletion docs/reference-docs/workflows/callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def create_l2vpn() -> StepList:
return (
begin
>> construct_model
>> store_process_subscription(Target.CREATE)
>> store_process_subscription()
>> callback_interaction(call_ansible_playbook)
>> set_status(SubscriptionLifecycle.ACTIVE)
)
Expand Down
2 changes: 1 addition & 1 deletion docs/workshops/beginner/create-user-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ UserGroup product. This is done by executing the following workflow steps:
```python
init
>> create_subscription
>> store_process_subscription(Target.CREATE)
>> store_process_subscription()
>> initialize_subscription
>> provision_user_group
>> set_status(SubscriptionLifecycle.ACTIVE)
Expand Down
2 changes: 1 addition & 1 deletion docs/workshops/beginner/create-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ initialize the subscription. This workflow uses the following steps:
```python
init
>> create_subscription
>> store_process_subscription(Target.CREATE)
>> store_process_subscription()
>> initialize_subscription
>> provision_user
>> set_status(SubscriptionLifecycle.ACTIVE)
Expand Down
2 changes: 1 addition & 1 deletion docs/workshops/beginner/modify-user-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ used:

```python
init
>> store_process_subscription(Target.MODIFY)
>> store_process_subscription()
>> unsync
>> modify_user_group_subscription
>> resync
Expand Down
2 changes: 1 addition & 1 deletion docs/workshops/beginner/modify-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This workflow uses the following steps:

```python
init
>> store_process_subscription(Target.MODIFY)
>> store_process_subscription()
>> unsync
>> modify_user_subscription
>> resync
Expand Down
2 changes: 1 addition & 1 deletion docs/workshops/beginner/terminate-user-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ customer, releasing all provisioned resources. The terminate workflow for the

```python
init
>> store_process_subscription(Target.TERMINATE)
>> store_process_subscription()
>> unsync
>> deprovision_user_group
>> set_status(SubscriptionLifecycle.TERMINATED)
Expand Down
2 changes: 1 addition & 1 deletion docs/workshops/beginner/terminate-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ steps:

```python
init
>> store_process_subscription(Target.TERMINATE)
>> store_process_subscription()
>> unsync
>> deprovision_user
>> set_status(SubscriptionLifecycle.TERMINATED)
Expand Down
3 changes: 1 addition & 2 deletions orchestrator/cli/generator/templates/create_product.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ from pydantic_forms.types import FormGenerator, State, UUIDstr

from orchestrator.forms import FormPage
from orchestrator.forms.validators import Divider, Label, CustomerId, MigrationSummary
from orchestrator.targets import Target
from orchestrator.types import SubscriptionLifecycle
from orchestrator.workflow import StepList, begin, step
from orchestrator.workflows.steps import store_process_subscription
Expand Down Expand Up @@ -119,6 +118,6 @@ def create_{{ product.variable }}() -> StepList:
return (
begin
>> construct_{{ product.variable }}_model
>> store_process_subscription(Target.CREATE)
>> store_process_subscription()
# TODO add provision step(s)
)
4 changes: 3 additions & 1 deletion orchestrator/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ class ProcessSubscriptionTable(BaseModel):
)
subscription_id = mapped_column(UUIDType, ForeignKey("subscriptions.subscription_id"), nullable=False, index=True)
created_at = mapped_column(UtcTimestamp, server_default=text("current_timestamp()"), nullable=False)
workflow_target = mapped_column(String(255), nullable=False, server_default=Target.CREATE)

# FIXME: workflow_target is already stored in the workflow table, this column should get removed in a later release.
workflow_target = mapped_column(String(255), nullable=True)

process = relationship("ProcessTable", back_populates="process_subscriptions")
subscription = relationship("SubscriptionTable", back_populates="processes")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Deprecating workflow target in ProcessSubscriptionTable.

Revision ID: 4b58e336d1bf
Revises: 161918133bec
Create Date: 2025-07-04 15:27:23.814954

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "4b58e336d1bf"
down_revision = "161918133bec"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.alter_column("processes_subscriptions", "workflow_target", existing_type=sa.VARCHAR(length=255), nullable=True)


def downgrade() -> None:
op.alter_column(
"processes_subscriptions",
"workflow_target",
existing_type=sa.VARCHAR(length=255),
nullable=False,
existing_server_default=sa.text("'CREATE'::character varying"),
)
2 changes: 1 addition & 1 deletion orchestrator/utils/enrich_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def enrich_process(process: ProcessTable, p_stat: ProcessStat | None = None) ->
"is_task": process.is_task,
"workflow_id": process.workflow_id,
"workflow_name": process.workflow.name,
"workflow_target": process.process_subscriptions[0].workflow_target if process.process_subscriptions else None,
"workflow_target": process.workflow.target,
"failed_reason": process.failed_reason,
"created_by": process.created_by,
"started_at": process.started_at,
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/workflows/modify_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def store_subscription_note(subscription_id: UUIDstr, note: str) -> State:

@workflow("Modify Note", initial_input_form=wrap_modify_initial_input_form(initial_input_form), target=Target.MODIFY)
def modify_note() -> StepList:
return init >> store_process_subscription(Target.MODIFY) >> store_subscription_note >> done
return init >> store_process_subscription() >> store_subscription_note >> done
19 changes: 11 additions & 8 deletions orchestrator/workflows/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,23 @@
return {"subscription": subscription}


def store_process_subscription_relationship(
process_id: UUIDstr, subscription_id: UUIDstr, workflow_target: str
) -> ProcessSubscriptionTable:
process_subscription = ProcessSubscriptionTable(
process_id=process_id, subscription_id=subscription_id, workflow_target=workflow_target
)
def store_process_subscription_relationship(process_id: UUIDstr, subscription_id: UUIDstr) -> ProcessSubscriptionTable:
process_subscription = ProcessSubscriptionTable(process_id=process_id, subscription_id=subscription_id)
db.session.add(process_subscription)
return process_subscription


def store_process_subscription(workflow_target: Target) -> Step:
def store_process_subscription(workflow_target: Target | None = None) -> Step:
if workflow_target:
deprecation_warning = (

Check warning on line 119 in orchestrator/workflows/steps.py

View check run for this annotation

Codecov / codecov/patch

orchestrator/workflows/steps.py#L119

Added line #L119 was not covered by tests
"Providing a workflow target to function store_process_subscription() is deprecated. "
"This information is already stored in the workflow table."
)
logger.warning(deprecation_warning)

Check warning on line 123 in orchestrator/workflows/steps.py

View check run for this annotation

Codecov / codecov/patch

orchestrator/workflows/steps.py#L123

Added line #L123 was not covered by tests

@step("Create Process Subscription relation")
def _store_process_subscription(process_id: UUIDstr, subscription_id: UUIDstr) -> None:
store_process_subscription_relationship(process_id, subscription_id, workflow_target)
store_process_subscription_relationship(process_id, subscription_id)

return _store_process_subscription

Expand Down
6 changes: 3 additions & 3 deletions orchestrator/workflows/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def modify_service_port():
def _modify_workflow(f: Callable[[], StepList]) -> Workflow:
steplist = (
init
>> store_process_subscription(Target.MODIFY)
>> store_process_subscription()
>> unsync
>> f()
>> (additional_steps or StepList())
Expand Down Expand Up @@ -311,7 +311,7 @@ def terminate_service_port():
def _terminate_workflow(f: Callable[[], StepList]) -> Workflow:
steplist = (
init
>> store_process_subscription(Target.TERMINATE)
>> store_process_subscription()
>> unsync
>> f()
>> (additional_steps or StepList())
Expand Down Expand Up @@ -348,7 +348,7 @@ def create_service_port():
"""

def _validate_workflow(f: Callable[[], StepList]) -> Workflow:
steplist = init >> store_process_subscription(Target.SYSTEM) >> unsync_unchecked >> f() >> resync >> done
steplist = init >> store_process_subscription() >> unsync_unchecked >> f() >> resync >> done

return make_workflow(f, description, validate_initial_input_form_generator, Target.VALIDATE, steplist)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from structlog import get_logger

from orchestrator.forms.validators import CustomerId
from orchestrator.targets import Target
from orchestrator.types import SubscriptionLifecycle
from orchestrator.workflow import StepList, begin, done, step, workflow
from orchestrator.workflows.steps import store_process_subscription
Expand Down Expand Up @@ -81,4 +80,4 @@ def construct_subscription_model(

@workflow("Create a test product", initial_input_form=wrap_create_initial_input_form(initial_input_form_generator))
def create_test_product() -> StepList:
return begin >> construct_subscription_model >> store_process_subscription(Target.CREATE) >> done
return begin >> construct_subscription_model >> store_process_subscription() >> done
2 changes: 1 addition & 1 deletion test/unit_tests/api/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def test_processes_filterable_response_model(
"current_state": None,
"steps": None,
"form": None,
"workflow_target": "CREATE",
"workflow_target": "SYSTEM",
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from orchestrator.domain import SubscriptionModel
from orchestrator.forms import FormPage
from orchestrator.forms.validators import CustomerId, Divider, Label
from orchestrator.targets import Target
from orchestrator.types import SubscriptionLifecycle
from orchestrator.workflow import StepList, begin, step
from orchestrator.workflows.steps import store_process_subscription
Expand Down Expand Up @@ -105,6 +104,6 @@ def construct_example1_model(
@create_workflow("Create example1", initial_input_form=initial_input_form_generator, additional_steps=additional_steps)
def create_example1() -> StepList:
return (
begin >> construct_example1_model >> store_process_subscription(Target.CREATE)
begin >> construct_example1_model >> store_process_subscription()
# TODO add provision step(s)
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from orchestrator.domain import SubscriptionModel
from orchestrator.forms import FormPage
from orchestrator.forms.validators import CustomerId, Divider, Label
from orchestrator.targets import Target
from orchestrator.types import SubscriptionLifecycle
from orchestrator.workflow import StepList, begin, step
from orchestrator.workflows.steps import store_process_subscription
Expand Down Expand Up @@ -74,6 +73,6 @@ def construct_example2_model(
@create_workflow("Create example2", initial_input_form=initial_input_form_generator, additional_steps=additional_steps)
def create_example2() -> StepList:
return (
begin >> construct_example2_model >> store_process_subscription(Target.CREATE)
begin >> construct_example2_model >> store_process_subscription()
# TODO add provision step(s)
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from orchestrator.domain import SubscriptionModel
from orchestrator.forms import FormPage
from orchestrator.forms.validators import CustomerId, Divider, Label
from orchestrator.targets import Target
from orchestrator.types import SubscriptionLifecycle
from orchestrator.workflow import StepList, begin, step
from orchestrator.workflows.steps import store_process_subscription
Expand Down Expand Up @@ -73,6 +72,6 @@ def construct_example4_model(
@create_workflow("Create example4", initial_input_form=initial_input_form_generator, additional_steps=additional_steps)
def create_example4() -> StepList:
return (
begin >> construct_example4_model >> store_process_subscription(Target.CREATE)
begin >> construct_example4_model >> store_process_subscription()
# TODO add provision step(s)
)
2 changes: 1 addition & 1 deletion test/unit_tests/fixtures/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def insert_object():

@step("Test that it is a string now")
def check_object(subscription_id: Any, model: dict) -> None:
# This is actually a test. It would be nicer to have this in a proper test but that takes to much setup that
# This is actually a test. It would be nicer to have this in a proper test but that takes too much setup that
# already happens here. So we hijack this fixture and run this test for all tests that use this fixture
# (which should not be an issue)
assert isinstance(subscription_id, str)
Expand Down