Skip to content

Commit

Permalink
Merge pull request #1030 from dimagi/sk/pipeline-assistant-version
Browse files Browse the repository at this point in the history
Convert assistant ID to str when creating pipeline versions
  • Loading branch information
snopoke authored Jan 8, 2025
2 parents 02b65aa + 878f94a commit 8e3ddb5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
9 changes: 7 additions & 2 deletions apps/pipelines/admin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
from django.contrib import admin

from .models import Pipeline, PipelineChatHistory, PipelineChatMessages, PipelineRun
from .models import Node, Pipeline, PipelineChatHistory, PipelineChatMessages, PipelineRun


class PipelineRunInline(admin.TabularInline):
model = PipelineRun
extra = 0


class PipelineNodeInline(admin.TabularInline):
model = Node
extra = 0


@admin.register(Pipeline)
class PipelineAdmin(admin.ModelAdmin):
inlines = [PipelineRunInline]
inlines = [PipelineNodeInline, PipelineRunInline]


class PipelineChatMessagesInline(admin.TabularInline):
Expand Down
24 changes: 24 additions & 0 deletions apps/pipelines/migrations/0011_migrate_assistant_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.db import migrations


def _update_assistant_id_type(apps, schema_editor):
Node = apps.get_model("pipelines", "Node")

for node in Node.objects.filter(type="AssistantNode").all():
if assistant_id := node.params.get("assistant_id"):
if isinstance(assistant_id, str):
continue

node.params["assistant_id"] = str(assistant_id)
node.save()


class Migration(migrations.Migration):

dependencies = [
('pipelines', '0010_auto_20241127_2042'),
]

operations = [
migrations.RunPython(_update_assistant_id_type, reverse_code=migrations.RunPython.noop)
]
3 changes: 2 additions & 1 deletion apps/pipelines/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ def create_new_version(self):
assistant = OpenAiAssistant.objects.get(id=new_version.params.get("assistant_id"))
if not assistant.is_a_version:
assistant_version = assistant.create_new_version()
new_version.params["assistant_id"] = assistant_version.id
# convert to string to be consistent with values from the UI
new_version.params["assistant_id"] = str(assistant_version.id)

new_version.save()
self._copy_custom_action_operations_to_new_version(new_node=new_version)
Expand Down
8 changes: 4 additions & 4 deletions apps/pipelines/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_versioning_assistant_node(self, versioned_assistant_linked):
assistant = assistant.create_new_version()

pipeline = PipelineFactory()
NodeFactory(type="AssistantNode", pipeline=pipeline, params={"assistant_id": assistant.id})
NodeFactory(type="AssistantNode", pipeline=pipeline, params={"assistant_id": str(assistant.id)})
assert pipeline.node_set.filter(type="AssistantNode").exists()

pipeline.create_new_version()
Expand All @@ -57,11 +57,11 @@ def test_versioning_assistant_node(self, versioned_assistant_linked):
node_version_assistant_id = node_version.params["assistant_id"]

if versioned_assistant_linked:
assert original_node_assistant_id == node_version_assistant_id == assistant.id
assert original_node_assistant_id == node_version_assistant_id == str(assistant.id)
else:
assert original_node_assistant_id != node_version_assistant_id
assert original_node_assistant_id == assistant.id
assert node_version_assistant_id == assistant_version.id
assert original_node_assistant_id == str(assistant.id)
assert node_version_assistant_id == str(assistant_version.id)


class TestPipeline:
Expand Down

0 comments on commit 8e3ddb5

Please sign in to comment.