Skip to content

CY-2430 Py3 porting: unicode/bytes changes#426

Merged
tehasdf merged 7 commits into
masterfrom
py3-test-fixes-3
Mar 4, 2020
Merged

CY-2430 Py3 porting: unicode/bytes changes#426
tehasdf merged 7 commits into
masterfrom
py3-test-fixes-3

Conversation

@tehasdf

@tehasdf tehasdf commented Mar 4, 2020

Copy link
Copy Markdown
Contributor

Only where absolutely necessary (for now)

See each commit for details

tehasdf added 7 commits March 4, 2020 15:05
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
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
@tehasdf tehasdf force-pushed the py3-test-fixes-3 branch from 1436f86 to 2b7df4f Compare March 4, 2020 14:52
@tehasdf tehasdf merged commit bfd1f21 into master Mar 4, 2020
@tehasdf tehasdf deleted the py3-test-fixes-3 branch March 4, 2020 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants