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

execnet.gateway_base.DumpError: can't serialize when string subclasses returned from __rep__ #1157

Closed
cjw296 opened this issue Nov 21, 2024 · 2 comments
Labels

Comments

@cjw296
Copy link

cjw296 commented Nov 21, 2024

This is a tricky one, here's a repro:

class StrSubclass(str):

    def fail(self):
        raise Exception()

    def __repr__(self):
        return self

def test_xdist_bug():
    StrSubclass('x').fail()

Then:

$ python3 -m pytest -n1 --dist loadfile  test_pytest_xdist_bug.py 
...
platform linux -- Python 3.12.2, pytest-8.1.1, pluggy-1.4.0
...
configfile: pytest.ini
plugins: xdist-3.3.1, timeout-2.3.1, cov-4.1.0, benchmark-4.0.0, anyio-4.4.0
...
INTERNALERROR> E               File "site-packages/execnet/gateway_base.py", line 1580, in save_tuple
INTERNALERROR> E                 self._save(item)
INTERNALERROR> E               File "site-packages/execnet/gateway_base.py", line 1503, in _save
INTERNALERROR> E                 raise DumpError(f"can't serialize {tp}")
INTERNALERROR> E             execnet.gateway_base.DumpError: can't serialize <class 'test_pytest_xdist_bug.StrSubclass'>
INTERNALERROR> E           assert False
INTERNALERROR> 
INTERNALERROR> site-packages/xdist/dsession.py:197: AssertionError

I'd argue that it's a bug that __repr__ here is returning something that isn't a string, but it's hard, because is is isinstance(..., str), but it's not type(...) is str, which is basically what execnet's dumps_internal currently requires.

Thought I'd throw this issue in to help others who may stumble down this path and maybe kick off a discussion.

@RonnyPfannschmidt
Copy link
Member

this one is a wontfix - the execnet serializer wont grow support for such types

@cjw296
Copy link
Author

cjw296 commented Nov 21, 2024

Hmm, it's not so much that the serializer needs to grow support for such types, but that there is a problem in the chain of reporting when using pytest-xdist.

My suspicion is that the issue actually lies in the traceback serialization that used to be in this package and is now in pytest itself, since it's that which is passing through a string subclass when it arguably shouldn't be.

That said, I appreciate this really is an edge case, so accept that any resolution is somewhat unlikely.

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

No branches or pull requests

2 participants