Skip to content

[heads up] test_pickle and test_pickle_does_not_pollute_cache fail when run with Python 3.15.0a6 (urllib.parse changes) #1632

@befeleme

Description

@befeleme

Please confirm the following

  • I understand this is open source software provided for free and that I might not receive a timely response.
  • I am positive I am NOT reporting a (potential) security
    vulnerability, to the best of my knowledge. (These must be shared by
    submitting this report form instead, if
    any hesitation exists.)
  • I am willing to submit a pull request with reporoducers as xfailing test cases or even entire fix. (Assign this issue to me.)

Describe the bug

I'm building yarl 1.22.0 in Fedora Linux 45 with Python 3.15.0a6.
Two tests fail. Based on the traceback, this will have something to do with the changes to urllib.parse: python/cpython@c5cfcdf
I don't know if it's regression on the side of Python or a functionality that needs to be worked into yarl's code.
Happy to test any fixes.

To Reproduce

in a fresh venv with Python 3.15.0a6:

$ python -m pip install pytest pytest_cov -e .
$ python -m pytest tests/test_pickle.py -W ignore::DeprecationWarning  # needed because current pygments leaks a DeprecationWarning

Expected behavior

Tests pass

Logs/tracebacks

_________________________________ test_pickle __________________________________
[gw0] linux -- Python 3.15.0 /usr/bin/python3

    def test_pickle() -> None:
        u1 = URL("picklepickle")
        hash(u1)
>       v = pickle.dumps(u1)
            ^^^^^^^^^^^^^^^^

u1         = URL('picklepickle')

tests/test_pickle.py:11: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = SplitResult(scheme='', netloc='', path='picklepickle', query='', fragment='')

    def __getstate__(self):
        state = super().__getstate__()
        try:
>           if state[1]['_keep_empty'] == _MISSING_AS_NONE_DEFAULT:
               ^^^^^^^^
E           TypeError: 'NoneType' object is not subscriptable
E           when serializing tuple item 0
E           when serializing yarl.URL state
E           when serializing yarl.URL object

__class__  = <class 'urllib.parse._ResultBase'>
self       = SplitResult(scheme='', netloc='', path='picklepickle', query='', fragment='')
state      = None

/usr/lib64/python3.15/urllib/parse.py:311: TypeError
______________________ test_pickle_does_not_pollute_cache ______________________
[gw0] linux -- Python 3.15.0 /usr/bin/python3

    def test_pickle_does_not_pollute_cache() -> None:
        """Verify the unpickling does not pollute the cache.
    
        Since unpickle will call URL.__new__ with default
        args, we need to make sure that default args never
        end up in the pre_encoded_url or encode_url cache.
        """
        u1 = URL.__new__(URL)
        u1._scheme = "this"
        u1._netloc = "never.appears.any.where.else.in.tests"
        u1._path = ""
        u1._query = ""
        u1._fragment = ""
        hash(u1)
>       v = pickle.dumps(u1)
            ^^^^^^^^^^^^^^^^

u1         = URL('this://never.appears.any.where.else.in.tests')

tests/test_pickle.py:48: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = SplitResult(scheme='this', netloc='never.appears.any.where.else.in.tests', path='', query='', fragment='')

    def __getstate__(self):
        state = super().__getstate__()
        try:
>           if state[1]['_keep_empty'] == _MISSING_AS_NONE_DEFAULT:
               ^^^^^^^^
E           TypeError: 'NoneType' object is not subscriptable
E           when serializing tuple item 0
E           when serializing yarl.URL state
E           when serializing yarl.URL object

__class__  = <class 'urllib.parse._ResultBase'>
self       = SplitResult(scheme='this', netloc='never.appears.any.where.else.in.tests', path='', query='', fragment='')
state      = None

Python Version

$ python --version
3.15.0a6

multidict Version

$ python -m pip show multidict
Version: 6.7.1

propcache Version

$ python -m pip show propcache

yarl Version

$ python -m pip show yarl
Version: 1.23.0 (tested on today's master)

OS

Fedora Linux 45/43

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions