Skip to content

pydantic dist.version is None causes TypeError: expected string or bytes-like object, got 'NoneType' #626

@Torxed

Description

@Torxed

This might be an issue in my environment, and it might belong in packaging but throwing out a question/bug report here just in case as I drew a judgement call that it's build supplying packaging with information in a potentially wrong way. And just to note if it matters, I'm managing packages via my operating system.

When I manually build pymilter I get the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/build/__main__.py", line 375, in main
    built = build_call(
            ^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/build/__main__.py", line 208, in build_package
    out = _build(isolation, builder, outdir, distribution, config_settings, skip_dependency_check)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/build/__main__.py", line 147, in _build
    return _build_in_current_env(builder, outdir, distribution, config_settings, skip_dependency_check)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/build/__main__.py", line 127, in _build_in_current_env
    missing = builder.check_dependencies(distribution)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/build/__init__.py", line 370, in check_dependencies
    return {u for d in dependencies for u in check_dependency(d)}
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/build/__init__.py", line 370, in <setcomp>
    return {u for d in dependencies for u in check_dependency(d)}
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/build/__init__.py", line 186, in check_dependency
    yield from check_dependency(other_req_string, ancestral_req_strings + (normalised_req_string,), req.extras)
  File "/usr/lib/python3.11/site-packages/build/__init__.py", line 186, in check_dependency
    yield from check_dependency(other_req_string, ancestral_req_strings + (normalised_req_string,), req.extras)
  File "/usr/lib/python3.11/site-packages/build/__init__.py", line 186, in check_dependency
    yield from check_dependency(other_req_string, ancestral_req_strings + (normalised_req_string,), req.extras)
  File "/usr/lib/python3.11/site-packages/build/__init__.py", line 180, in check_dependency
    if req.specifier and not req.specifier.contains(dist.version, prereleases=True):
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/packaging/specifiers.py", line 905, in contains
    item = Version(item)
           ^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/packaging/version.py", line 196, in __init__
    match = self._regex.search(version)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

ERROR expected string or bytes-like object, got 'NoneType'

(The source of build is modified by adding one print just to see what package and/or version was causing the hiccup)
Here, dist.version becomes None for pydantic specifically in this case:

build/src/build/__init__.py

Lines 173 to 179 in cd06da2

try:
dist = importlib_metadata.distribution(req.name) # type: ignore[no-untyped-call]
except importlib_metadata.PackageNotFoundError:
# dependency is not installed in the environment.
yield ancestral_req_strings + (normalised_req_string,)
else:
if req.specifier and not req.specifier.contains(dist.version, prereleases=True):

It feels either like a bug in pydantic not presenting the version in the right way, or build for passing in unexpected data to packaging or packaging not handling the case. But what if anything is wrong with my environment? And how to debug/correct this, as I most likely have more packages down the line that will produce the same issue.

Steps to potentially reproduce:

anton@bigrigv2 ~/github $ git clone [email protected]:sdgathman/pymilter.git
anton@bigrigv2 ~/github $ cd pymilter/
anton@bigrigv2 ~/github/pymilter (master)$ python -m build --wheel --no-isolation
* Getting build dependencies for wheel...
running egg_info
creating pymilter.egg-info
writing pymilter.egg-info/PKG-INFO
writing dependency_links to pymilter.egg-info/dependency_links.txt
writing top-level names to pymilter.egg-info/top_level.txt
writing manifest file 'pymilter.egg-info/SOURCES.txt'
reading manifest file 'pymilter.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'milter-template.py'
warning: no files found matching 'start.sh'
adding license file 'COPYING'
writing manifest file 'pymilter.egg-info/SOURCES.txt'
wheel version: 0.40.0
setuptools version: 68.0.0
platformdirs version: 3.5.1
jaraco.text version: 3.11.1
jaraco.functools version: 3.7.0
more-itertools version: 9.1.0
jaraco.context version: 4.3.0
autocommand version: 2.2.2
inflect version: 6.0.4
pydantic version: None

My environment:

  • Python --version = 3.11.3
  • pydantic.__version__ = '1.10.9'
  • python-build = 0.10.0-4
  • python-packaging = 23.1-1
  • python-installer = 0.7.0-3
  • Arch Linux = 2023-06-25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions