Skip to content

Commit c6a2e73

Browse files
authored
For #43024: Handles an old core with a version of “HEAD” in its info.yml. (shotgunsoftware#467)
In this case, we don't know if the target tk-core is new or old. We attempt to treat it as "new" and use the modern code path for bootstrapping the Shotgun engine. If that fails, then we also try to fall back to the legacy pathway. This should be exceedingly rare, as it would require a locked-off site config that contains a tk-core that's been cloned from Github, rather than being pulled from the Toolkit app store.
1 parent 3d17032 commit c6a2e73

File tree

1 file changed

+63
-23
lines changed

1 file changed

+63
-23
lines changed

python/tank/bootstrap/manager.py

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
from ..pipelineconfig import PipelineConfiguration
2020
from .. import LogManager
2121
from ..errors import TankError
22-
from ..util.version import is_version_older
22+
from ..util.version import is_version_older, is_version_head
23+
from ..platform.errors import TankEngineInitError
2324

2425
log = LogManager.get_logger(__name__)
2526

@@ -921,39 +922,78 @@ def _start_engine(self, tk, engine_name, entity, progress_callback=None):
921922

922923
# perform absolute import to ensure we get the new swapped core.
923924
import tank
925+
is_shotgun_engine = engine_name == constants.SHOTGUN_ENGINE_NAME
924926

925927
# handle legacy cases
926-
if engine_name == constants.SHOTGUN_ENGINE_NAME and is_version_older(tk.version, "v0.18.77"):
927-
928-
# bootstrapping into a shotgun engine with an older core
929-
# we perform this special check to make sure that we correctly pick up
930-
# the shotgun_xxx.yml environment files, even for older cores.
931-
# new cores handles all this inside the tank.platform.start_shotgun_engine
932-
# business logic.
933-
log.debug(
934-
"Target core version is %s. Starting shotgun engine via legacy pathway." % tk.version
935-
)
936-
937-
if entity is None:
938-
raise TankBootstrapError(
939-
"Legacy shotgun environments do not support bootstrapping into a site context."
940-
)
941-
942-
# start engine via legacy pathway
943-
# note the local import due to core swapping.
944-
from tank.platform import engine
945-
engine = engine.start_shotgun_engine(tk, entity["type"], ctx)
946-
928+
if is_shotgun_engine and is_version_older(tk.version, "v0.18.77"):
929+
engine = self._legacy_start_shotgun_engine(tk, engine_name, entity, ctx)
947930
else:
948931
# no legacy cases
949-
engine = tank.platform.start_engine(engine_name, tk, ctx)
932+
try:
933+
engine = tank.platform.start_engine(engine_name, tk, ctx)
934+
except TankEngineInitError as exc:
935+
# It's possible that a tk-core is being used that didn't come from
936+
# the app_store. This might be the case where a site config has been
937+
# locked off, and populated with a tk-core cloned from Github. In that
938+
# case, it'll have "HEAD" as its version. In that situation, we don't
939+
# actually know if this is a "new" core, or something super old. Given
940+
# that, we need to try going the legacy route here just to see if we
941+
# might actually have an old core.
942+
if is_version_head(tk.version) and is_shotgun_engine:
943+
try:
944+
engine = self._legacy_start_shotgun_engine(tk, engine_name, entity, ctx)
945+
except Exception:
946+
# We'll want to raise the original exception here. We don't
947+
# really know whether this is a legacy core or not, so if both
948+
# the legacy and new code paths failed, we'll raise the exception
949+
# from the new code path.
950+
log.warning(
951+
"Attempted legacy engine start path for Shotgun engine, which failed. "
952+
"This attempt was made because the tk-core version is HEAD, which means "
953+
"we don't know if it's new or old. As such, when the new-style bootstrap "
954+
"failed, the legacy pathway was attempted."
955+
)
956+
raise exc
957+
else:
958+
# In this case, we know we're in a new enough core, but that we
959+
# just failed for some legitimate reason.
960+
raise exc
950961

951962
log.debug("Launched engine %r" % engine)
952963

953964
self._report_progress(progress_callback, self._BOOTSTRAP_COMPLETED, "Engine launched.")
954965

955966
return engine
956967

968+
def _legacy_start_shotgun_engine(self, tk, engine_name, entity, ctx):
969+
"""
970+
Starts the tk-shotgun engine by way of the legacy "start_shotgun_engine"
971+
method provided by tank.platform.engine.
972+
973+
:param tk: Bootstrapped :class:`~sgtk.Sgtk` instance.
974+
:param engine_name: Name of the engine to start up.
975+
:param entity: Shotgun entity used to resolve a project context.
976+
:type entity: Dictionary with keys ``type`` and ``id``, or ``None`` for the site.
977+
"""
978+
# bootstrapping into a shotgun engine with an older core
979+
# we perform this special check to make sure that we correctly pick up
980+
# the shotgun_xxx.yml environment files, even for older cores.
981+
# new cores handles all this inside the tank.platform.start_shotgun_engine
982+
# business logic.
983+
log.debug(
984+
"Target core version is %s. Starting shotgun engine via legacy pathway." % tk.version
985+
)
986+
987+
if entity is None:
988+
raise TankBootstrapError(
989+
"Legacy shotgun environments do not support bootstrapping into a site context."
990+
)
991+
992+
# start engine via legacy pathway
993+
# note the local import due to core swapping.
994+
from tank.platform import engine
995+
return engine.start_shotgun_engine(tk, entity["type"], ctx)
996+
957997
def _report_progress(self, progress_callback, progress_value, message):
958998
"""
959999
Helper method that reports back on the bootstrap progress to a defined progress callback.

0 commit comments

Comments
 (0)