-
Notifications
You must be signed in to change notification settings - Fork 116
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
[BUG] Python3 incompatibilities #146
Comments
@ixs Thanks for raising this issue. We've got well-structured automated testing available on this formula and I believe the way to tackle this is to formally define the problem with failing tests. If you're not familiar with InSpec, that's not a problem -- if you can provide me with the inputs (pillar/config) and outputs (rendered files), If you look at our current matrix, we're actually testing https://travis-ci.com/github/saltstack-formulas/bind-formula/builds/154561467 We've still got the pre-salted |
The underlying problem is the following:
This would happen for example if you define the following data in your pillar (soa etc. omitted for brevity):
The first record in the yaml file is cast as an integer, the second one as a string. |
@ixs Thanks, I'll rustle up a failing test or two and then get back to you. |
@myii thanks, it's been a while since I last worked with inspec and you're probably much quicker in whipping up a test-case. :-) |
@ixs First bit of feedback. This was enough to trigger the error: myii@485880a. https://travis-ci.org/github/myii/bind-formula/builds/670517157: All of the tracebacks in the failing job returned back to this line, which isn't highlighting the records: {{ zone_records | json }} <====================== Added another tiny commit to get through to the https://travis-ci.org/github/myii/bind-formula/builds/670520245: The failing job contains the traceback returning back to the Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/utils/templates.py", line 394, in render_jinja_tmpl
output = template.render(**decoded_context)
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 35, in top-level template code
File "/usr/lib/python3/dist-packages/jinja2/filters.py", line 222, in do_dictsort
return sorted(value.items(), key=sort_func)
TypeError: unorderable types: str() < int()
; line 35
---
[...]
{% else %}
{% for type, rrs in records|dictsort %}
;
; {{ type }} RRs
;
{%- for host, data in rrs|dictsort %} <======================
If the sorting is of great significance, then there's always the option of using lists but that's heavy-handed and a lot of hassle for everyone in terms of having to modify their pillars. If necessary, I can add another test to check for the ordering as well. Otherwise, at this stage, number 2 seems like the better option, since that avoids errors and pillar modification. CC: @daks, your feedback would be useful here. |
@myii yeah, the | json error I spotted too but it never was clear to me why it is breaking. But I also did not dig deep enough. I agree that option 2, removing dictsort is the best approach. Since python3.6 (IIRC) dicts are preserving the order of insertion of keys and are not random anymore. |
saltstack-formulas/users-formula#219 (comment) Relevant here as well, that |
I ran into the following on Py 3.6.9. (salt 3001) using a pillar with 2 views defined:
Removing |dictsort from the
Changing line 204 to the following resolves the 'bool' issue with
If you also remove dictsort (line 206), the following error is given:
|
With a quick "find and replace" I've replaced all uses of This seems to have resolved this issue for me. If removing Edit: I missed also removing the |
@daks That was probably because you provided #129 so I must have thought you used the formula back then. No worries, the general situation is understood, we just need to finalise how we resolve this.
@bcrisp4 Thanks for the offer, I think that's the right way forward. @ixs Are you good with that? |
When running this formula under python3, multiple issues crop up:
dictsort is used extensively and has changed functionality between py2 and py3. Python2 would happily sort a dictionary containing both strings and integers. Python3 however will return a TypeError saying that int and str are incompatible types.
This is a known change in the sorted() function.
{{ zone_records | tojson }} seems to break on mixed data as well. I did not dig into the reason yet.
There are two possible ways of resolving the issue:
Document that zone data must be all strings. Especially when configuring PTR RRs. Instead of using an int as key, this needs to be wrapped in quotes to ensure there are only strings. This ill work but has the drawback that e.g. '110' is now seen as smaller than e.g. '40' and the order of entries in the zone files appear incorrectly sorted.
Remove all use of dictsort and instead rely on the python3 behavior that dicts are now returned in deterministic (but not sorted) order.
What is the preferred solution?
For 2. an example patch might look like this:
The text was updated successfully, but these errors were encountered: