Skip to content

Commit 3c5e599

Browse files
committed
feat: [SG-43418] Replace env var side channel with show_dialog parameters
The Loader previously used TK_FLOWAM_REVISION_ID_* environment variables to pass am_revision_id to the Publisher, which caused race conditions when multiple Publisher dialogs were open simultaneously. Replace with clean parameter passing via show_dialog(context, root_item_properties): - When publishing new generic asset: pass entity_ctx so Publisher can pre-fill the context widget and use task/entity for MEDM hierarchy placement. - When publishing existing generic asset revision: pass context=None and root_item_properties={"am_revision_id": revision_id} so the publish hook receives the correct asset identifier without env vars or shared state.
1 parent 4aff39a commit 3c5e599

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

hooks/tk-desktop_actions.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Hook that loads defines all the available actions, broken down by publish type.
1313
"""
1414

15-
import os
1615
from typing import Any
1716

1817
import sgtk
@@ -281,23 +280,6 @@ def _launch_publisher(self, action_name: str, sg_publish_data: dict) -> None:
281280
else:
282281
raise TankError(f"Invalid entity type for publish: {entity_type}.")
283282

284-
# Use different env var naming for project-level vs task-level contexts
285-
if task_id is not None:
286-
revision_id_env_var = f"TK_FLOWAM_REVISION_ID_{task_id}"
287-
else:
288-
# For project-level contexts, use project ID
289-
project_id = entity_id
290-
revision_id_env_var = f"TK_FLOWAM_REVISION_ID_PROJECT_{project_id}"
291-
292-
if action_name == "publish":
293-
revision_id = sg_publish_data.get("sg_flow_revision_id")
294-
os.environ[revision_id_env_var] = revision_id
295-
else:
296-
# Clear possible previously existing publish states from an unfinished publish
297-
# (Finished publishes should clear this value)
298-
if revision_id_env_var in os.environ:
299-
os.environ.pop(revision_id_env_var)
300-
301283
# NOTE: the context should be either a Task or a Project
302284
entity_ctx = engine.tank.context_from_entity(entity_type, entity_id)
303285

@@ -307,13 +289,27 @@ def _launch_publisher(self, action_name: str, sg_publish_data: dict) -> None:
307289
continue
308290
if cmd_settings["properties"]["app"].name == "tk-multi-publish2":
309291
publisher_app = cmd_settings["properties"]["app"]
292+
revision_id = sg_publish_data.get("sg_flow_revision_id")
310293
single_file_mode = (
311294
action_name == "publish"
312295
and publisher_app.context.flow_project_id is not None
313296
)
314-
publisher_app.import_module("tk_multi_publish2").show_dialog(
315-
publisher_app, single_file_mode=single_file_mode
316-
)
297+
if revision_id:
298+
# Existing flowam asset revision - target identified by am_revision_id only, no FPT context needed.
299+
publisher_app.import_module("tk_multi_publish2").show_dialog(
300+
publisher_app,
301+
context=None,
302+
root_item_properties={"am_revision_id": revision_id},
303+
single_file_mode=single_file_mode,
304+
)
305+
else:
306+
# New flowam asset - pass FPT context for pre-fill and MEDM hierarchy placement.
307+
publisher_app.import_module("tk_multi_publish2").show_dialog(
308+
publisher_app,
309+
context=entity_ctx,
310+
root_item_properties=None,
311+
single_file_mode=single_file_mode,
312+
)
317313
break
318314
else:
319315
raise TankError(

0 commit comments

Comments
 (0)