CY-2430 Py3 porting: unicode/bytes changes#426
Merged
Conversation
Inside of events, the message is interpolated into a native string, so there's no need to encode it. Later, it is sent via rabbitmq, as json, ie. unicode, so encoding it to bytes makes no sense at all. Without this change, on py3, we see logs with the repr'd `b''` prefix
and so we must make sure we cope with bytes there. In the future, we can think about whether it doesn't make more sense to return unicode there instead
cope with bytes there, instead of unicode/native strings
the zmq and http proxies have their assumptions where do bytes go and where does unicode go, now python 3 forces us to actually adhere to that
warn is deprecated
ctx.returns already used `-j` however the input data wasn't json,
but it is now.
This means that it is now actually possible to pass things back,
such as dicts, and they will not be stringified in a silly way. Also,
unicode objects can be passed, and ints, and...
For compatibility, things that cannot be jsonified (eg. like in the
tests, type/class objects), are repr'd and passed as string still.
That is silly, but it is backwards-compatible at least.
Since what is returned now is eg. a real dict, and not a string
representation of it, in ctx.returns we also pass an empty dict,
because otherwise the MutableMapping tango could want to use the
actual data as kwargs
In tests we can now assert actual objects and not ast.literal_eval
and other sillyness.
Two caveats with the test asserts:
- it's <type int> on py2 but <class int> on py3, so just make the
string comparison work with both
- the test method we have returns `result or runtime_properties`,
so falsy objects are wrapped in a {"value": ..} so that they
can actually be asserted on (otherwise we'd get runtime props
instead of the return value, in the test)
Note btw, `ctx.returns()` is a very underused feature because the
only way to really use it, is to have your custom workflow do
something like `value = operation.get()`, and there's no way of
using it with tasks graphs
in py3 it's "FileNotFoundError", not "IOError", in the error message
1436f86 to
2b7df4f
Compare
geokala
approved these changes
Mar 4, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Only where absolutely necessary (for now)
See each commit for details