Skip to content

reverse priority of path entries#692

Merged
pingsutw merged 3 commits intomainfrom
daniel/reverse-path-addition
Feb 23, 2026
Merged

reverse priority of path entries#692
pingsutw merged 3 commits intomainfrom
daniel/reverse-path-addition

Conversation

@dansola
Copy link
Contributor

@dansola dansola commented Feb 20, 2026

Bug: adjust_sys_path reverses FLYTE_SYS_PATH priority order

Root cause
_run.py builds FLYTE_SYS_PATH by iterating the local sys.path in order — highest-priority entries first. adjust_sys_path on the remote then processes those entries with sys.path.insert(0, p) one by one. Because each insert pushes previous entries down, the last entry in FLYTE_SYS_PATH ends up at position 0 (highest priority) which is the exact opposite of the local ordering.

cli/_common.py appends the entrypoint file's parent directory to sys.path so the module can be imported. That directory is therefore the last entry captured into FLYTE_SYS_PATH. On the remote container it becomes the first entry in sys.path, giving it higher priority than the project root and causing any same-named modules inside that directory to shadow top-level packages.

I think this bug occurs whenever you run flyte run with an entrypoint that's not at the project root. e.g. flyte run workflows/foo.py rather than flyte run foo.py.

Fix
Collect all FLYTE_SYS_PATH entries into a list first, then iterate in reverse before calling sys.path.insert(0, p). This way the first entry in FLYTE_SYS_PATH (highest local priority) is inserted last and ends up at position 0 on the remote which is matching the local ordering.

entries = [p for p in os.environ.get(FLYTE_SYS_PATH, "").split(":") if p and p not in sys.path]
for p in reversed(entries):
    sys.path.insert(0, p)

pingsutw
pingsutw previously approved these changes Feb 23, 2026
Copy link
Member

@pingsutw pingsutw left a comment

Choose a reason for hiding this comment

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

LGTM, thanks, could you fix the lint errors

@pingsutw pingsutw merged commit 6a07b39 into main Feb 23, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants