Skip to content
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

Fixes #1712: Fix content_view_version_cleanup slice error #1713

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

smeeus
Copy link
Contributor

@smeeus smeeus commented Feb 23, 2024

An explicit conversion to int of the foreman_content_view_version_cleanup_keep variable is required to fix the slice indices must be integers or None or have an __index__ method error.

@smeeus smeeus changed the title Fixes #1712: Fix content_view_version_cleanup slice error Closes #1712: Fix content_view_version_cleanup slice error Feb 23, 2024
@smeeus smeeus changed the title Closes #1712: Fix content_view_version_cleanup slice error Fixes #1712: Fix content_view_version_cleanup slice error Feb 23, 2024
@smeeus
Copy link
Contributor Author

smeeus commented Feb 23, 2024

@evgeni Could you try and prioritize this fix in one of the next releases please?

@evgeni
Copy link
Member

evgeni commented Feb 23, 2024

How are you setting it so it doesn't end up being an int?

@smeeus
Copy link
Contributor Author

smeeus commented Feb 23, 2024

Very good question, and I don't have an answer there. I have had this error for a long while now and actually never considered that it was due to that variable being an issue.
It's only today by really debugging all the selectattr, rejectattr and map filters that I figured out it was related to this variable.
When I debug the variable, it does show as an integer, but it seems it doesn't when you use it to slice the lists.
There might be moregoing on, but the implicit conversion does work.
In the issue, I've used 0 as a value, but I've also tested the fix with 1 and 3 against a satellite 6.14 server.

@evgeni
Copy link
Member

evgeni commented Feb 23, 2024

This feels like papering over an actual issue.

In our CI this works just fine:

And so does my prod environment where I use this role regularly.

Do your variables come from some external source, not a vars file?

@smeeus
Copy link
Contributor Author

smeeus commented Feb 23, 2024

I always set it from command line with -e "foreman_content_view_version_cleanup_keep=0"
In the production environments I work with, it passes through another collection I am working on: https://github.com/kangaroot/ansible-collection-kangaroot-foreman

But even with the example playbook in the issue, I have the same error.

@evgeni
Copy link
Member

evgeni commented Feb 23, 2024

out of curiousity, can you try with -e '{"foreman_content_view_version_cleanup_keep":5}' (= use JSON and not a string to pass the var)

@smeeus
Copy link
Contributor Author

smeeus commented Feb 23, 2024

I don't have the error if I use the JSON style parameter.
I've also tried some variations with single and double quotes on the non-JSON style and they all give the same error.

This is one of those python variable type conversion things again I think...

Something I have issues with on a regular basis is ansible_distribution_major_version >= 8 for example in when clauses, they also need an implicit conversion to int everywhere I check for a version these days. I use different ansible versions in some cases (customer dependent). Something tells me this is somewhat related and python not having proper knowledge of the type of the variables.

@smeeus
Copy link
Contributor Author

smeeus commented Feb 23, 2024

Now, regardless of the JSON style working or not, I can imagine that other people might have faced the same issue.
Even though it is pampering something that shouldn't be fixed, it might be a good idea to just do it regardless, always be sure that it is an int instead of having to rely on a certain method of passing command line variables etc.

@evgeni
Copy link
Member

evgeni commented Feb 23, 2024

Yeah, I absolutely agree we should fix this. I just wanted to better understand why it needs fixing.

The cli -e string/json difference is a good one.

@evgeni evgeni merged commit 7e8a7d9 into theforeman:develop Feb 23, 2024
12 of 23 checks passed
@smeeus
Copy link
Contributor Author

smeeus commented Feb 23, 2024

Thanks @evgeni

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants