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
Cannot substitute Int
only Str
in recipe
#895
Comments
The problem appears to be in here: autopkg/Code/autopkglib/__init__.py Lines 466 to 470 in e7bdfe1
|
I don't actually know if this is a good idea or what the implications might be, but this does seem to fix this specific issue:
|
This addresses the error when trying to do variable substitution with an Int: autopkg#895 Not sure what other implications this could have.
I just submitted a PR that addresses this, though I am just now realizing this does NOT address the boolean case, which I just tested, due to the way I have it written. In the boolean case, you get:
|
I just realized I could also fix this issue by adding a processor:
I still think it would be nice if autopkg handled this transparently though, but this lets you handle it explicitly. |
Just skiming through here and happened to come across this issue and it's related PR. It looks very similar to the issue that I described and submitted a PR for in #911. Does this sound accurate @jgstew ? I'm also not sure if my PR has the correct "assumption" in mind when it comes to the expectations of substitution variables. |
@MLBZ521 I do think your PR is related, but not exactly the same, though I'm uncertain. From looking over your PR, it seems like it should be the processor that handles the case better. This PR is more about handling the case where variable substitution is being used with non strings and should apply to both YAML and non YAML I think? I couldn't quite tell if your issue related to variable substitution specifically or not? |
I think it's both. The Processor could be written to handle the types better....but if AutoPkg (proper) was updated to handle What my PR is proposing is:
This allows the Processors to still expect However, my PR may be to "heavy" on converting everything to a |
But yes -- my PR is specifically for YAML only. |
Maybe I'm misunderstanding but we definitely don't want autopkg to behave differently if a recipe happens to be formatted in yaml versus one formatted as a plist. I think I agree that autopkg should just convert all values to strings before doing string substitution, even when doing so might have "interesting" consequences. (Like converting an array of strings into a string). Those consequences are really on the recipe writer to anticipate. Alternately, we could convert only "scalar" types and not lists/arrays or dictionaries. |
I think we're on the same page Greg. It's which direction would be the preferred way to go:
|
So the way I was proposing handling this is to attempt to convert variables into strings ONLY when doing substitution, but otherwise their type would be maintained. I think this is important because I do have processors that set variables as non strings and operate on them as non strings intentionally (dictionaries, arrays) I basically figured out some options for when the variable substitution function throws an error, then at that point attempt to convert the items to a string and do it again. This addresses the issue regardless of YAML or Plist recipe. |
Yeah, I think long term adjusting the In the short term, I've proposed an new solution for YAML recipes in #929. This solution is the latter option in my previous reply on 12/7/2023. |
Describe the problem
If you try to substitute anything other than a string using %substitution% within a recipe, autopkg throws an error, even for things like
Int
orBoolean
that are easily represented as strings.As far as I know this has ALWAYS been the case with autopkg, but it is quite annoying.
Consider this recipe example: https://github.com/jgstew/jgstew-recipes/blob/main/Test-Recipes/IntSubtitution.test.recipe.yaml
This does NOT happen if
Number: "123"
is used instead ofNumber: 123
Preferences contents
N/A
AutoPkg output
Expected behavior
I expect autopkg to turn the
int
value into a string and substitute it into the variable.Version (please complete the following information):
The text was updated successfully, but these errors were encountered: