Skip to content

Update pydantic version to 2.13#319

Merged
rwb27 merged 3 commits into
mainfrom
bump-pydantic-minimum-version
Apr 28, 2026
Merged

Update pydantic version to 2.13#319
rwb27 merged 3 commits into
mainfrom
bump-pydantic-minimum-version

Conversation

@rwb27
Copy link
Copy Markdown
Collaborator

@rwb27 rwb27 commented Apr 27, 2026

This bumps the minimum version of Pydantic to 2.13, which should avoid an upstream bug in earlier versions.

Closes #283

This bumps the minimum version of Pydantic to 2.13, which should avoid an upstream bug in earlier versions.

Closes #283
@barecheck
Copy link
Copy Markdown

barecheck Bot commented Apr 27, 2026

Barecheck - Code coverage report

Total: 96.64%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@rwb27
Copy link
Copy Markdown
Collaborator Author

rwb27 commented Apr 27, 2026

@julianstirling do you have a reproducible example I can run (or add to the test suite) to verify that updating Pydantic does actually fix the bug? If you're happy we just need to update the requirement, I'm happy to merge as-is.

@julianstirling
Copy link
Copy Markdown
Contributor

@julianstirling do you have a reproducible example I can run (or add to the test suite) to verify that updating Pydantic does actually fix the bug? If you're happy we just need to update the requirement, I'm happy to merge as-is.

The issue is that if we use ImportString to import a file that imports a file that doesn't exist. It reports that the first file doesn't exist, rather than the actual missing file. To unit test this we would need to monkeypatch the systempath. The test that checks this in Pydantic is:

def test_importstring_reports_internal_import_error(tmp_path, monkeypatch):
    # Create a module that exists, but fails to import due to missing dependency
    (tmp_path / 'my_module.py').write_text('import definitely_missing_dep_xyz\n\nclass MyClass:\n    pass\n')
    monkeypatch.syspath_prepend(tmp_path)

    adapter = TypeAdapter(ImportString)

    with pytest.raises(ValidationError, match="No module named 'definitely_missing_dep_xyz'"):
        adapter.validate_python('my_module.MyClass')

@rwb27 rwb27 force-pushed the bump-pydantic-minimum-version branch from dbcdff4 to 3470397 Compare April 28, 2026 10:08
@rwb27 rwb27 force-pushed the bump-pydantic-minimum-version branch from 3470397 to cfd2efb Compare April 28, 2026 10:08
@rwb27
Copy link
Copy Markdown
Collaborator Author

rwb27 commented Apr 28, 2026

The issue is that if we use ImportString to import a file that imports a file that doesn't exist. It reports that the first file doesn't exist, rather than the actual missing file.

This was surprisingly straightforward to do: I've already got a module of unimportable submodules used to test this, so I've added one specifically for this error. I think this is ready now, assuming the tests pass.

@rwb27
Copy link
Copy Markdown
Collaborator Author

rwb27 commented Apr 28, 2026

I have run the newly-parametrized test with both pydantic~=2.13 (which is what we require) and pydantic==2.12. I can confirm that the older version does not pass the tests due to incorrect error messages, and the newer version does.

@rwb27 rwb27 merged commit 04c28d8 into main Apr 28, 2026
15 checks passed
@rwb27 rwb27 deleted the bump-pydantic-minimum-version branch April 28, 2026 10:42
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.

Pydantic ImportString can report the incorrect missing file

3 participants