-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[master] Fix urlunparse for salt file urls on python-3.12 #66948
Conversation
a4baa23
to
023e875
Compare
Essentially duplicate of #66899 |
salt/utils/url.py
Outdated
return "salt://{}".format(url[len("file:///") :]) | ||
url = salt.utils.data.decode(urlunparse(("salt", "", path, "", query, ""))) | ||
# urllib returns `salt:` but salt wants `salt://`, so normalize here | ||
if url.startswith("salt:{path}"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the f
: if url.startswith(f"salt:{path}"):
salt/utils/url.py
Outdated
@@ -46,8 +46,11 @@ def create(path, saltenv=None): | |||
path = salt.utils.data.decode(path) | |||
|
|||
query = f"saltenv={saltenv}" if saltenv else "" | |||
url = salt.utils.data.decode(urlunparse(("file", "", path, "", query, ""))) | |||
return "salt://{}".format(url[len("file:///") :]) | |||
url = salt.utils.data.decode(urlunparse(("salt", "", path, "", query, ""))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that you can safely just replace "file"
with "salt"
. There is special handling for a file
scheme; I am not sure the extent of what is different but it could affect how the path and query are handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, reverted to original format with file:
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read through the urlunparse source code and there does not appear to be any current special handling of the file
scheme as far as transforming the path or query so it would be safe to replace with salt
(ignoring future changes that add special cases for file if some bug was discovered)
Previously, the `salt.utils.url.create()` method naively assumed the compiled URL provided by `urllib.parse.urlunparse()` always starts with the literal string `file:///`, that is, the begininning of the URL string starting with the `scheme` and including an empty `authority` section. Beginning with [python-3.12](python/cpython@0edfc66), however, generating a URL with `urlunparse()` results in the syntax `file:` for the portion of the URL including the `scheme` and `authority` sections.
Hey, Justin... good to see you in here. Would you mind creating this against the 3006.x branch. |
Duplicate of #66899. |
What does this PR do?
Previously, the
salt.utils.url.create()
method naively assumed the compiled URL provided byurllib.parse.urlunparse()
always starts with the literal stringfile:///
, that is, the begininning of the URL string starting with thescheme
and including an emptyauthority
section. Beginning with python-3.12, however, generating a URL withurlunparse()
results in the syntaxfile:
for the portion of the URL including thescheme
andauthority
sections.Since
urlunparse()
accepts the arbitrary schemesalt
, use it instead and then normalize the rendered scheme tosalt://
as SaltStack expects.Without this change, salt can't even find its own top file:
Previous Behavior
New Behavior
Commits signed with GPG?
Yes