Skip to content

Commit 0f69a5a

Browse files
committed
Fix Python3.13 compatibility regarding urllib.parse module
Python 3.13 fixed handling relative paths in urllib.parse module. Specifically, relative file URL is now constructed as file:path instead of converting it to absolute file:///path. This breaks salt.utils.url.create which expects file:/// specifically. The mismatch results in for example changing salt://top.sls into salt://.sls and thus not finding the top file. Fix this by handling both prefixes. Relevant python change: python/cpython#85110 Fixes: saltstack#66898
1 parent 221420c commit 0f69a5a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

changelog/66898.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed Python 3.13 compatibility regarding urllib.parse module

salt/utils/url.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import re
66
import sys
7-
from urllib.parse import urlparse, urlunparse
7+
from urllib.parse import urlparse, urlunparse, urlunsplit
88

99
import salt.utils.data
1010
import salt.utils.path
@@ -46,8 +46,7 @@ def create(path, saltenv=None):
4646
path = salt.utils.data.decode(path)
4747

4848
query = f"saltenv={saltenv}" if saltenv else ""
49-
url = salt.utils.data.decode(urlunparse(("file", "", path, "", query, "")))
50-
return "salt://{}".format(url[len("file:///") :])
49+
return f'salt://{salt.utils.data.decode(urlunsplit(("", "", path, query, "")))}'
5150

5251

5352
def is_escaped(url):

0 commit comments

Comments
 (0)