From 44aa8757d654033e4254124af1c50df95a591762 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Tue, 15 Oct 2024 15:00:31 -0400 Subject: [PATCH 01/26] new pydantic matrix --- .github/workflows/main.yml | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b619dd94b..6575047dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -98,6 +98,48 @@ jobs: path: coverage include-hidden-files: true + test-pydantic: + name: test on ${{ matrix.pydantic-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + pydantic-version: ["2.6.4", "2.7.4", "2.8.2", "2.9.2"] + steps: + - uses: actions/checkout@v4 + + - name: Ensure requests to production domains fail + if: runner.os == 'Linux' + run: | + echo "203.0.113.0 logfire.dev" | sudo tee -a /etc/hosts + echo "203.0.113.0 logfire-api.pydantic.dev" | sudo tee -a /etc/hosts + echo "203.0.113.0 logfire.pydantic.dev" | sudo tee -a /etc/hosts + + - name: Install uv + uses: astral-sh/setup-uv@v3 + with: + version: "0.4.12" + enable-cache: true + + - name: Set up Python 3.12 + run: uv python install 3.12 + + - name: Install pydantic ${{ matrix.pydantic-version }} + run: uv pip install pydantic==${{ matrix.pydantic-version }} + + - run: uv sync --python 3.12 --upgrade + + - run: mkdir coverage + - run: make test + env: + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-pydantic-${{ matrix.pydantic-version }} + - name: store coverage files + uses: actions/upload-artifact@v4 + with: + name: coverage-pydantic-${{ matrix.pydantic-version }} + path: coverage + include-hidden-files: true + coverage: runs-on: ubuntu-latest needs: [test] From d39bfeca72e49229209e414840bca0ea1921a9d6 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Tue, 15 Oct 2024 15:05:13 -0400 Subject: [PATCH 02/26] more helpful title --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6575047dd..117bfc04f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -99,11 +99,12 @@ jobs: include-hidden-files: true test-pydantic: - name: test on ${{ matrix.pydantic-version }} + name: test with pydantic ${{ matrix.pydantic-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: + # keep up to date with 3-4 latest pydantic versions pydantic-version: ["2.6.4", "2.7.4", "2.8.2", "2.9.2"] steps: - uses: actions/checkout@v4 From 2c0fe7af903303bdf6c747625bc6f9398fad7330 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Tue, 15 Oct 2024 15:07:49 -0400 Subject: [PATCH 03/26] swap order --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 117bfc04f..87e477879 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -125,11 +125,11 @@ jobs: - name: Set up Python 3.12 run: uv python install 3.12 + - run: uv sync --python 3.12 --upgrade + - name: Install pydantic ${{ matrix.pydantic-version }} run: uv pip install pydantic==${{ matrix.pydantic-version }} - - run: uv sync --python 3.12 --upgrade - - run: mkdir coverage - run: make test env: From da710eaec857f4675f23e53b82e898d172cfcbc1 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Wed, 16 Oct 2024 21:46:19 +0100 Subject: [PATCH 04/26] update pydantic versions and remove nocover stmts --- .github/workflows/main.yml | 3 +-- logfire/_internal/main.py | 2 +- logfire/integrations/pydantic.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 87e477879..83e220e66 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -104,8 +104,7 @@ jobs: strategy: fail-fast: false matrix: - # keep up to date with 3-4 latest pydantic versions - pydantic-version: ["2.6.4", "2.7.4", "2.8.2", "2.9.2"] + pydantic-version: ["1.10.18", "2.4.2", "2.5.3", "2.6.4", "2.7.4", "2.8.2", "2.9.2"] steps: - uses: actions/checkout@v4 diff --git a/logfire/_internal/main.py b/logfire/_internal/main.py index b97cd524b..d5d1d9275 100644 --- a/logfire/_internal/main.py +++ b/logfire/_internal/main.py @@ -832,7 +832,7 @@ def instrument_pydantic( if record != 'off': import pydantic - if get_version(pydantic.__version__) < get_version('2.5.0'): # pragma: no cover + if get_version(pydantic.__version__) < get_version('2.5.0'): raise RuntimeError('The Pydantic plugin requires Pydantic 2.5.0 or newer.') from logfire.integrations.pydantic import PydanticPlugin, set_pydantic_plugin_config diff --git a/logfire/integrations/pydantic.py b/logfire/integrations/pydantic.py index 4cd5e3819..614f8b9da 100644 --- a/logfire/integrations/pydantic.py +++ b/logfire/integrations/pydantic.py @@ -298,7 +298,7 @@ class LogfirePydanticPlugin: if ( get_version(pydantic.__version__) < get_version('2.5.0') or os.environ.get('LOGFIRE_PYDANTIC_RECORD') == 'off' - ): # pragma: no cover + ): def new_schema_validator( # type: ignore[reportRedeclaration] self, *_: Any, **__: Any From 6220c269bf0ff7f663d5956c0e6748ec68325f5a Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Wed, 16 Oct 2024 21:47:59 +0100 Subject: [PATCH 05/26] add to check --- .github/workflows/main.yml | 2 +- logfire/integrations/pydantic.py | 4 +--- uv.lock | 8 +++----- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 83e220e66..657938c89 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -177,7 +177,7 @@ jobs: # https://github.com/marketplace/actions/alls-green#why used for branch protection checks check: if: always() - needs: [lint, docs, test, coverage] + needs: [lint, docs, test, test-pydantic, coverage] runs-on: ubuntu-latest steps: - name: Decide whether the needed jobs succeeded or failed diff --git a/logfire/integrations/pydantic.py b/logfire/integrations/pydantic.py index 614f8b9da..8e39b2e8e 100644 --- a/logfire/integrations/pydantic.py +++ b/logfire/integrations/pydantic.py @@ -296,9 +296,7 @@ class LogfirePydanticPlugin: `PYDANTIC_DISABLE_PLUGINS` to `true` to disable all Pydantic plugins. """ - if ( - get_version(pydantic.__version__) < get_version('2.5.0') or os.environ.get('LOGFIRE_PYDANTIC_RECORD') == 'off' - ): + if get_version(pydantic.__version__) < get_version('2.5.0') or os.environ.get('LOGFIRE_PYDANTIC_RECORD') == 'off': def new_schema_validator( # type: ignore[reportRedeclaration] self, *_: Any, **__: Any diff --git a/uv.lock b/uv.lock index ef451bb0e..9a0e0ec25 100644 --- a/uv.lock +++ b/uv.lock @@ -431,7 +431,7 @@ name = "cffi" version = "1.17.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "pycparser" }, + { name = "pycparser", marker = "platform_python_implementation != 'PyPy' or python_full_version >= '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/fc/97/c783634659c2920c3fc70419e3af40972dbaf758daa229a7d6ea6135c90d/cffi-1.17.1.tar.gz", hash = "sha256:1c39c6016c32bc48dd54561950ebd6836e1670f2ae46128f67cf49e789c52824", size = 516621 } wheels = [ @@ -1365,7 +1365,7 @@ wheels = [ [[package]] name = "logfire" -version = "1.0.1" +version = "1.1.0" source = { editable = "." } dependencies = [ { name = "executing" }, @@ -1612,7 +1612,7 @@ dev = [ [[package]] name = "logfire-api" -version = "1.0.1" +version = "1.1.0" source = { editable = "logfire-api" } [[package]] @@ -2775,8 +2775,6 @@ version = "6.0.0" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/18/c7/8c6872f7372eb6a6b2e4708b88419fb46b857f7a2e1892966b851cc79fc9/psutil-6.0.0.tar.gz", hash = "sha256:8faae4f310b6d969fa26ca0545338b21f73c6b15db7c4a8d934a5482faa818f2", size = 508067 } wheels = [ - { url = "https://files.pythonhosted.org/packages/c5/66/78c9c3020f573c58101dc43a44f6855d01bbbd747e24da2f0c4491200ea3/psutil-6.0.0-cp27-none-win32.whl", hash = "sha256:02b69001f44cc73c1c5279d02b30a817e339ceb258ad75997325e0e6169d8b35", size = 249766 }, - { url = "https://files.pythonhosted.org/packages/e1/3f/2403aa9558bea4d3854b0e5e567bc3dd8e9fbc1fc4453c0aa9aafeb75467/psutil-6.0.0-cp27-none-win_amd64.whl", hash = "sha256:21f1fb635deccd510f69f485b87433460a603919b45e2a324ad65b0cc74f8fb1", size = 253024 }, { url = "https://files.pythonhosted.org/packages/0b/37/f8da2fbd29690b3557cca414c1949f92162981920699cd62095a984983bf/psutil-6.0.0-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:c588a7e9b1173b6e866756dde596fd4cad94f9399daf99ad8c3258b3cb2b47a0", size = 250961 }, { url = "https://files.pythonhosted.org/packages/35/56/72f86175e81c656a01c4401cd3b1c923f891b31fbcebe98985894176d7c9/psutil-6.0.0-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ed2440ada7ef7d0d608f20ad89a04ec47d2d3ab7190896cd62ca5fc4fe08bf0", size = 287478 }, { url = "https://files.pythonhosted.org/packages/19/74/f59e7e0d392bc1070e9a70e2f9190d652487ac115bb16e2eff6b22ad1d24/psutil-6.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5fd9a97c8e94059b0ef54a7d4baf13b405011176c3b6ff257c247cae0d560ecd", size = 290455 }, From cc1a84fb5cf1466da1471d619c7d4e6831c791bd Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Wed, 16 Oct 2024 21:53:50 +0100 Subject: [PATCH 06/26] combine, mega matrix --- .github/workflows/main.yml | 46 ++++---------------------------------- 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 657938c89..d4bb9081a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,6 +64,7 @@ jobs: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + pydantic-version: ["1.10.18", "2.4.2", "2.5.3", "2.6.4", "2.7.4", "2.8.2", "2.9.2"] env: PYTHON: ${{ matrix.python-version }} steps: @@ -87,56 +88,17 @@ jobs: - run: uv sync --python ${{ matrix.python-version }} --upgrade - - run: mkdir coverage - - run: make test - env: - COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }} - - name: store coverage files - uses: actions/upload-artifact@v4 - with: - name: coverage-${{ matrix.python-version }} - path: coverage - include-hidden-files: true - - test-pydantic: - name: test with pydantic ${{ matrix.pydantic-version }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - pydantic-version: ["1.10.18", "2.4.2", "2.5.3", "2.6.4", "2.7.4", "2.8.2", "2.9.2"] - steps: - - uses: actions/checkout@v4 - - - name: Ensure requests to production domains fail - if: runner.os == 'Linux' - run: | - echo "203.0.113.0 logfire.dev" | sudo tee -a /etc/hosts - echo "203.0.113.0 logfire-api.pydantic.dev" | sudo tee -a /etc/hosts - echo "203.0.113.0 logfire.pydantic.dev" | sudo tee -a /etc/hosts - - - name: Install uv - uses: astral-sh/setup-uv@v3 - with: - version: "0.4.12" - enable-cache: true - - - name: Set up Python 3.12 - run: uv python install 3.12 - - - run: uv sync --python 3.12 --upgrade - - name: Install pydantic ${{ matrix.pydantic-version }} run: uv pip install pydantic==${{ matrix.pydantic-version }} - run: mkdir coverage - run: make test env: - COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-pydantic-${{ matrix.pydantic-version }} + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-pydantic${{ matrix.pydantic-version }} - name: store coverage files uses: actions/upload-artifact@v4 with: - name: coverage-pydantic-${{ matrix.pydantic-version }} + name: coverage-${{ matrix.python-version }} path: coverage include-hidden-files: true @@ -177,7 +139,7 @@ jobs: # https://github.com/marketplace/actions/alls-green#why used for branch protection checks check: if: always() - needs: [lint, docs, test, test-pydantic, coverage] + needs: [lint, docs, test, coverage] runs-on: ubuntu-latest steps: - name: Decide whether the needed jobs succeeded or failed From 219c72820c35b6d06e845d7ae9a69217b1566809 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Wed, 16 Oct 2024 21:54:26 +0100 Subject: [PATCH 07/26] minor patch --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d4bb9081a..a2aa7343e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -98,7 +98,7 @@ jobs: - name: store coverage files uses: actions/upload-artifact@v4 with: - name: coverage-${{ matrix.python-version }} + name: coverage-py${{ matrix.python-version }}-pydantic${{ matrix.pydantic-version }} path: coverage include-hidden-files: true From 1ed317d91eed686d412accbe44c067c043bfb858 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Wed, 16 Oct 2024 21:57:04 +0100 Subject: [PATCH 08/26] name update --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a2aa7343e..6ec95aebd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,7 +58,7 @@ jobs: fi test: - name: test on ${{ matrix.python-version }} + name: test on Python ${{ matrix.python-version }} and pydantic v${{ matrix.pydantic-version }} runs-on: ubuntu-latest strategy: fail-fast: false From 8323589b48f7bc075835d3dce50505e5d36a55f5 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Thu, 17 Oct 2024 15:10:57 +0100 Subject: [PATCH 09/26] add tests for other versions on 3.12 --- .github/workflows/main.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ec95aebd..c01d146c0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,7 +64,22 @@ jobs: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - pydantic-version: ["1.10.18", "2.4.2", "2.5.3", "2.6.4", "2.7.4", "2.8.2", "2.9.2"] + pydantic-version: "git+https://github.com/pydantic/pydantic.git" + include: + - python-version: '3.12' + pydantic-version: '1.10.18' + - python-version: '3.12' + pydantic-version: '2.4.2' + - python-version: '3.12' + pydantic-version: '2.5.3' + - python-version: '3.12' + pydantic-version: '2.6.4' + - python-version: '3.12' + pydantic-version: '2.7.4' + - python-version: '3.12' + pydantic-version: '2.8.2' + - python-version: '3.12' + pydantic-version: '2.9.2' env: PYTHON: ${{ matrix.python-version }} steps: From 9fb5364d558b737b074af2073359c16c3a0c51a6 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Thu, 17 Oct 2024 15:13:27 +0100 Subject: [PATCH 10/26] conditional cleanup --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c01d146c0..ce25eeaaf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,7 +64,7 @@ jobs: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - pydantic-version: "git+https://github.com/pydantic/pydantic.git" + pydantic-version: "main" include: - python-version: '3.12' pydantic-version: '1.10.18' @@ -104,6 +104,7 @@ jobs: - run: uv sync --python ${{ matrix.python-version }} --upgrade - name: Install pydantic ${{ matrix.pydantic-version }} + if: matrix.pydantic-version != 'main' run: uv pip install pydantic==${{ matrix.pydantic-version }} - run: mkdir coverage From 92289d9fb3cb94550568ed6541c64ad7cd72548e Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Thu, 17 Oct 2024 15:14:08 +0100 Subject: [PATCH 11/26] update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ce25eeaaf..f81180089 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,7 +64,7 @@ jobs: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - pydantic-version: "main" + pydantic-version: 'main' include: - python-version: '3.12' pydantic-version: '1.10.18' From 6f84eadb9b6ce466f135ec784582a344ecbec93f Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Thu, 17 Oct 2024 15:17:06 +0100 Subject: [PATCH 12/26] add dashes for clarity --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f81180089..fbed85e9d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -110,11 +110,11 @@ jobs: - run: mkdir coverage - run: make test env: - COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-pydantic${{ matrix.pydantic-version }} + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version }} - name: store coverage files uses: actions/upload-artifact@v4 with: - name: coverage-py${{ matrix.python-version }}-pydantic${{ matrix.pydantic-version }} + name: coverage-py${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version }} path: coverage include-hidden-files: true From 659677c77927630c5ce83f6e317ade74efd70107 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Thu, 17 Oct 2024 16:45:42 +0200 Subject: [PATCH 13/26] Update .github/workflows/main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fbed85e9d..c3200b1a6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,7 +64,7 @@ jobs: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - pydantic-version: 'main' + pydantic-version: ['main'] include: - python-version: '3.12' pydantic-version: '1.10.18' From cba079cc88d6457b854ded3079902caf783ec59f Mon Sep 17 00:00:00 2001 From: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:49:35 -0400 Subject: [PATCH 14/26] Update .github/workflows/main.yml Co-authored-by: Alex Hall --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c3200b1a6..c157e88a1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,7 +58,7 @@ jobs: fi test: - name: test on Python ${{ matrix.python-version }} and pydantic v${{ matrix.pydantic-version }} + name: test on Python ${{ matrix.python-version }} and pydantic ${{ matrix.pydantic-version }} runs-on: ubuntu-latest strategy: fail-fast: false From 5f0817aca7652c73effbcd7f62c7a439f37601ee Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Thu, 17 Oct 2024 15:58:14 +0100 Subject: [PATCH 15/26] install most recent patch --- .github/workflows/main.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fbed85e9d..4daba633c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,17 +69,17 @@ jobs: - python-version: '3.12' pydantic-version: '1.10.18' - python-version: '3.12' - pydantic-version: '2.4.2' + pydantic-version: '2.4.0' - python-version: '3.12' - pydantic-version: '2.5.3' + pydantic-version: '2.5.0' - python-version: '3.12' - pydantic-version: '2.6.4' + pydantic-version: '2.6.0' - python-version: '3.12' - pydantic-version: '2.7.4' + pydantic-version: '2.7.0' - python-version: '3.12' - pydantic-version: '2.8.2' + pydantic-version: '2.8.0' - python-version: '3.12' - pydantic-version: '2.9.2' + pydantic-version: '2.9.0' env: PYTHON: ${{ matrix.python-version }} steps: @@ -105,7 +105,8 @@ jobs: - name: Install pydantic ${{ matrix.pydantic-version }} if: matrix.pydantic-version != 'main' - run: uv pip install pydantic==${{ matrix.pydantic-version }} + # installs the most recent patch on the minor version's track, ex 2.6.0 -> 2.6.4 + run: uv pip install 'pydantic~=${{ matrix.pydantic-version }}' - run: mkdir coverage - run: make test From 48919eaad23f9cc85b84c5a5f560e2845b8a8c17 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Thu, 17 Oct 2024 16:02:51 +0100 Subject: [PATCH 16/26] more intuitive naming --- .github/workflows/main.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bc2568eef..9d618d6fe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,17 +69,17 @@ jobs: - python-version: '3.12' pydantic-version: '1.10.18' - python-version: '3.12' - pydantic-version: '2.4.0' + pydantic-version: '2.4' - python-version: '3.12' - pydantic-version: '2.5.0' + pydantic-version: '2.5' - python-version: '3.12' - pydantic-version: '2.6.0' + pydantic-version: '2.6' - python-version: '3.12' - pydantic-version: '2.7.0' + pydantic-version: '2.7' - python-version: '3.12' - pydantic-version: '2.8.0' + pydantic-version: '2.8' - python-version: '3.12' - pydantic-version: '2.9.0' + pydantic-version: '2.9' env: PYTHON: ${{ matrix.python-version }} steps: @@ -106,7 +106,7 @@ jobs: - name: Install pydantic ${{ matrix.pydantic-version }} if: matrix.pydantic-version != 'main' # installs the most recent patch on the minor version's track, ex 2.6.0 -> 2.6.4 - run: uv pip install 'pydantic~=${{ matrix.pydantic-version }}' + run: uv pip install 'pydantic==${{ matrix.pydantic-version }}.*' - run: mkdir coverage - run: make test From bb363616caa6abf384b2a9b4ef2b781ac941bd39 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Thu, 17 Oct 2024 16:08:23 +0100 Subject: [PATCH 17/26] v1 pragma removal --- logfire/_internal/json_encoder.py | 2 +- logfire/_internal/json_schema.py | 2 +- logfire/_internal/main.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/logfire/_internal/json_encoder.py b/logfire/_internal/json_encoder.py index 8ed6b9529..6a95395f7 100644 --- a/logfire/_internal/json_encoder.py +++ b/logfire/_internal/json_encoder.py @@ -155,7 +155,7 @@ def _pydantic_model_encoder(o: Any, seen: set[int]) -> JsonValue: assert isinstance(o, pydantic.BaseModel) try: dump = o.model_dump() - except AttributeError: # pragma: no cover + except AttributeError: # pydantic v1 dump = o.dict() # type: ignore return to_json_value(dump, seen) diff --git a/logfire/_internal/json_schema.py b/logfire/_internal/json_schema.py index 3dbfbfb08..501477d90 100644 --- a/logfire/_internal/json_schema.py +++ b/logfire/_internal/json_schema.py @@ -276,7 +276,7 @@ def _pydantic_model_schema(obj: Any, seen: set[int]) -> JsonDict: try: fields = obj.model_fields extra = obj.model_extra or {} - except AttributeError: # pragma: no cover + except AttributeError: # pydantic v1 fields = obj.__fields__ # type: ignore extra = {} diff --git a/logfire/_internal/main.py b/logfire/_internal/main.py index d5d1d9275..1a3d1a455 100644 --- a/logfire/_internal/main.py +++ b/logfire/_internal/main.py @@ -1886,7 +1886,7 @@ def _record_exception( # insert a more detailed breakdown of pydantic errors try: err_json = exception.json(include_url=False) - except TypeError: # pragma: no cover + except TypeError: # pydantic v1 err_json = exception.json() span.set_attribute(ATTRIBUTES_VALIDATION_ERROR_KEY, err_json) From a45b7271d93573a8b32d56655430c57ffff051bd Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Fri, 18 Oct 2024 12:08:47 +0100 Subject: [PATCH 18/26] run with uv explicit command --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9d618d6fe..c11b4e3b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -109,7 +109,7 @@ jobs: run: uv pip install 'pydantic==${{ matrix.pydantic-version }}.*' - run: mkdir coverage - - run: make test + - run: uv run --no-sync coverage run -m pytest env: COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version }} - name: store coverage files From c4147058f566152ec8fc86c16727cc47c351b3e7 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Fri, 18 Oct 2024 12:53:30 +0100 Subject: [PATCH 19/26] fix tests for v2.4 --- tests/test_configure.py | 3 +++ tests/test_logfire_api.py | 4 ++++ tests/test_pydantic_plugin.py | 14 +++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/test_configure.py b/tests/test_configure.py index 08c5ced20..913b31a1f 100644 --- a/tests/test_configure.py +++ b/tests/test_configure.py @@ -30,6 +30,7 @@ SpanExportResult, ) from opentelemetry.trace import get_tracer_provider +from pydantic import __version__ as pydantic_version from pytest import LogCaptureFixture import logfire @@ -51,6 +52,7 @@ from logfire._internal.exporters.wrapper import WrapperSpanExporter from logfire._internal.integrations.executors import deserialize_config, serialize_config from logfire._internal.tracer import PendingSpanProcessor +from logfire._internal.utils import get_version from logfire.exceptions import LogfireConfigError from logfire.integrations.pydantic import get_pydantic_plugin_config from logfire.testing import TestExporter @@ -422,6 +424,7 @@ def fresh_pydantic_plugin(): return get_pydantic_plugin_config() +@pytest.mark.skipif(get_version(pydantic_version) < get_version('2.5.0')) def test_pydantic_plugin_include_exclude_strings(): logfire.instrument_pydantic(include='inc', exclude='exc') assert fresh_pydantic_plugin().include == {'inc'} diff --git a/tests/test_logfire_api.py b/tests/test_logfire_api.py index 94e4882b6..51da2a9d9 100644 --- a/tests/test_logfire_api.py +++ b/tests/test_logfire_api.py @@ -8,6 +8,9 @@ from unittest.mock import MagicMock import pytest +from pydantic import __version__ as pydantic_version + +from logfire._internal.utils import get_version def logfire_dunder_all() -> set[str]: @@ -29,6 +32,7 @@ def import_logfire_api_with_logfire() -> ModuleType: return importlib.reload(logfire_api) +@pytest.mark.skipif(get_version(pydantic_version) < get_version('2.5.0')) @pytest.mark.parametrize( ['logfire_api_factory', 'module_name'], [ diff --git a/tests/test_pydantic_plugin.py b/tests/test_pydantic_plugin.py index 34d194e1a..3d5c7b805 100644 --- a/tests/test_pydantic_plugin.py +++ b/tests/test_pydantic_plugin.py @@ -6,6 +6,7 @@ from unittest.mock import patch import cloudpickle +import pydantic import pytest from dirty_equals import IsInt from inline_snapshot import snapshot @@ -14,7 +15,6 @@ from pydantic import BaseModel, ConfigDict, ValidationError, field_validator from pydantic.dataclasses import dataclass as pydantic_dataclass from pydantic.functional_validators import AfterValidator -from pydantic.plugin import PydanticPluginProtocol, SchemaTypePath, ValidatePythonHandlerProtocol from pydantic.type_adapter import TypeAdapter from pydantic_core import core_schema from typing_extensions import Annotated @@ -22,6 +22,7 @@ import logfire import logfire.integrations.pydantic from logfire._internal.config import GLOBAL_CONFIG +from logfire._internal.utils import get_version from logfire.integrations.pydantic import ( LogfirePydanticPlugin, get_schema_name, @@ -29,6 +30,17 @@ from logfire.testing import SeededRandomIdGenerator, TestExporter from tests.test_metrics import get_collected_metrics +pytestmark = pytest.mark.skipif( + get_version(pydantic.__version__) < get_version('2.5.0'), + reason='Skipping all tests except plugin warning test for versions less than 2.5.', +) + +try: + from pydantic.plugin import PydanticPluginProtocol, SchemaTypePath, ValidatePythonHandlerProtocol +except ImportError: + if not get_version(pydantic.__version__) < get_version('2.5.0'): + raise + def test_plugin_listed(): found = True From 886c66ff10f56ce494db54f3f79444596d3428ac Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Fri, 18 Oct 2024 13:13:42 +0100 Subject: [PATCH 20/26] fixing tests? --- tests/test_configure.py | 4 +++- tests/test_logfire_api.py | 2 +- tests/test_pydantic_plugin.py | 24 ++++++++++++++++-------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/test_configure.py b/tests/test_configure.py index 913b31a1f..bbb3f76cb 100644 --- a/tests/test_configure.py +++ b/tests/test_configure.py @@ -424,7 +424,9 @@ def fresh_pydantic_plugin(): return get_pydantic_plugin_config() -@pytest.mark.skipif(get_version(pydantic_version) < get_version('2.5.0')) +@pytest.mark.skipif( + get_version(pydantic_version) < get_version('2.5.0'), reason='skipping for pydantic versions < v2.5' +) def test_pydantic_plugin_include_exclude_strings(): logfire.instrument_pydantic(include='inc', exclude='exc') assert fresh_pydantic_plugin().include == {'inc'} diff --git a/tests/test_logfire_api.py b/tests/test_logfire_api.py index 51da2a9d9..29c7170a9 100644 --- a/tests/test_logfire_api.py +++ b/tests/test_logfire_api.py @@ -32,7 +32,7 @@ def import_logfire_api_with_logfire() -> ModuleType: return importlib.reload(logfire_api) -@pytest.mark.skipif(get_version(pydantic_version) < get_version('2.5.0')) +@pytest.mark.skipif(get_version(pydantic_version) < get_version('2.5.0'), reason='Skipping on Pydantic versions < v2.5') @pytest.mark.parametrize( ['logfire_api_factory', 'module_name'], [ diff --git a/tests/test_pydantic_plugin.py b/tests/test_pydantic_plugin.py index 3d5c7b805..64c49c354 100644 --- a/tests/test_pydantic_plugin.py +++ b/tests/test_pydantic_plugin.py @@ -2,20 +2,25 @@ import importlib.metadata import os -from typing import Any +from typing import TYPE_CHECKING, Any from unittest.mock import patch import cloudpickle -import pydantic import pytest from dirty_equals import IsInt from inline_snapshot import snapshot from opentelemetry.sdk.metrics.export import AggregationTemporality, InMemoryMetricReader from opentelemetry.sdk.trace.export import SimpleSpanProcessor -from pydantic import BaseModel, ConfigDict, ValidationError, field_validator +from pydantic import ( + AfterValidator, + BaseModel, + ConfigDict, + TypeAdapter, + ValidationError, + __version__ as pydantic_version, + field_validator, +) from pydantic.dataclasses import dataclass as pydantic_dataclass -from pydantic.functional_validators import AfterValidator -from pydantic.type_adapter import TypeAdapter from pydantic_core import core_schema from typing_extensions import Annotated @@ -31,14 +36,17 @@ from tests.test_metrics import get_collected_metrics pytestmark = pytest.mark.skipif( - get_version(pydantic.__version__) < get_version('2.5.0'), - reason='Skipping all tests except plugin warning test for versions less than 2.5.', + get_version(pydantic_version) < get_version('2.5.0'), + reason='Skipping all tests for versions less than 2.5.', ) +if TYPE_CHECKING: + from pydantic.plugin import PydanticPluginProtocol, SchemaTypePath, ValidatePythonHandlerProtocol + try: from pydantic.plugin import PydanticPluginProtocol, SchemaTypePath, ValidatePythonHandlerProtocol except ImportError: - if not get_version(pydantic.__version__) < get_version('2.5.0'): + if not get_version(pydantic_version) < get_version('2.5.0'): raise From 089969338fe4535653f79c602a8d27b60cbd47df Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Fri, 18 Oct 2024 13:16:05 +0100 Subject: [PATCH 21/26] remove v1 crap --- .github/workflows/main.yml | 2 -- logfire/_internal/json_encoder.py | 2 +- logfire/_internal/json_schema.py | 2 +- logfire/_internal/main.py | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c11b4e3b4..01e1015ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,8 +66,6 @@ jobs: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] pydantic-version: ['main'] include: - - python-version: '3.12' - pydantic-version: '1.10.18' - python-version: '3.12' pydantic-version: '2.4' - python-version: '3.12' diff --git a/logfire/_internal/json_encoder.py b/logfire/_internal/json_encoder.py index 6a95395f7..8ed6b9529 100644 --- a/logfire/_internal/json_encoder.py +++ b/logfire/_internal/json_encoder.py @@ -155,7 +155,7 @@ def _pydantic_model_encoder(o: Any, seen: set[int]) -> JsonValue: assert isinstance(o, pydantic.BaseModel) try: dump = o.model_dump() - except AttributeError: + except AttributeError: # pragma: no cover # pydantic v1 dump = o.dict() # type: ignore return to_json_value(dump, seen) diff --git a/logfire/_internal/json_schema.py b/logfire/_internal/json_schema.py index 501477d90..3dbfbfb08 100644 --- a/logfire/_internal/json_schema.py +++ b/logfire/_internal/json_schema.py @@ -276,7 +276,7 @@ def _pydantic_model_schema(obj: Any, seen: set[int]) -> JsonDict: try: fields = obj.model_fields extra = obj.model_extra or {} - except AttributeError: + except AttributeError: # pragma: no cover # pydantic v1 fields = obj.__fields__ # type: ignore extra = {} diff --git a/logfire/_internal/main.py b/logfire/_internal/main.py index d5aba9ff8..878dea9d1 100644 --- a/logfire/_internal/main.py +++ b/logfire/_internal/main.py @@ -1915,7 +1915,7 @@ def _record_exception( # insert a more detailed breakdown of pydantic errors try: err_json = exception.json(include_url=False) - except TypeError: + except TypeError: # pragma: no cover # pydantic v1 err_json = exception.json() span.set_attribute(ATTRIBUTES_VALIDATION_ERROR_KEY, err_json) From 83f48138ddc09e9265106b44cb06b6ca6244dada Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Fri, 18 Oct 2024 13:21:07 +0100 Subject: [PATCH 22/26] more stupid pass --- tests/test_pydantic_plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_pydantic_plugin.py b/tests/test_pydantic_plugin.py index 64c49c354..b952f8263 100644 --- a/tests/test_pydantic_plugin.py +++ b/tests/test_pydantic_plugin.py @@ -46,8 +46,8 @@ try: from pydantic.plugin import PydanticPluginProtocol, SchemaTypePath, ValidatePythonHandlerProtocol except ImportError: - if not get_version(pydantic_version) < get_version('2.5.0'): - raise + # it's fine, pydantic version Date: Fri, 18 Oct 2024 13:32:51 +0100 Subject: [PATCH 23/26] coverage test --- tests/test_logfire.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_logfire.py b/tests/test_logfire.py index 5a887aac2..35bd85641 100644 --- a/tests/test_logfire.py +++ b/tests/test_logfire.py @@ -17,7 +17,7 @@ from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import BatchSpanProcessor, SimpleSpanProcessor from opentelemetry.trace import StatusCode -from pydantic import BaseModel +from pydantic import BaseModel, __version__ as pydantic_version from pydantic_core import ValidationError import logfire @@ -2583,3 +2583,9 @@ def test_force_flush(exporter: TestExporter): logfire.force_flush() assert len(exporter.exported_spans_as_dict()) == 1 + + +@pytest.mark.skipif(pydantic_version != '2.4.2') +def test_instrument_pydantic_on_2_5() -> None: + with pytest.raises(RuntimeError, match='The Pydantic plugin requires Pydantic 2.5.0 or newer.'): + logfire.instrument_pydantic() From 7f6221362a080c8b10745e54bb226082aac5b9e8 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Fri, 18 Oct 2024 13:38:13 +0100 Subject: [PATCH 24/26] please work --- tests/test_logfire.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_logfire.py b/tests/test_logfire.py index 35bd85641..84d53d89c 100644 --- a/tests/test_logfire.py +++ b/tests/test_logfire.py @@ -2585,7 +2585,10 @@ def test_force_flush(exporter: TestExporter): assert len(exporter.exported_spans_as_dict()) == 1 -@pytest.mark.skipif(pydantic_version != '2.4.2') +@pytest.mark.skipif( + pydantic_version != '2.4.2', # type: ignore + reason='just testing compatibility with versions less that Pydantic v2.5.0', +) def test_instrument_pydantic_on_2_5() -> None: with pytest.raises(RuntimeError, match='The Pydantic plugin requires Pydantic 2.5.0 or newer.'): logfire.instrument_pydantic() From e3fb61092ef5aad193b294296ca347fbd4156f22 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Fri, 18 Oct 2024 13:50:26 +0100 Subject: [PATCH 25/26] alex's request --- tests/test_logfire_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_logfire_api.py b/tests/test_logfire_api.py index 29c7170a9..aa8c31cfb 100644 --- a/tests/test_logfire_api.py +++ b/tests/test_logfire_api.py @@ -32,7 +32,6 @@ def import_logfire_api_with_logfire() -> ModuleType: return importlib.reload(logfire_api) -@pytest.mark.skipif(get_version(pydantic_version) < get_version('2.5.0'), reason='Skipping on Pydantic versions < v2.5') @pytest.mark.parametrize( ['logfire_api_factory', 'module_name'], [ @@ -141,7 +140,10 @@ def func() -> None: ... for member in [m for m in logfire__all__ if m.startswith('instrument_')]: assert hasattr(logfire_api, member), member - getattr(logfire_api, member)() + if get_version(pydantic_version) >= get_version('2.5.0') and member == 'instrument_pydantic': + # skip pydantic instrumentation (which uses the plugin) for versions prior to v2.5 + getattr(logfire_api, member)() + # just remove the member unconditionally to pass future asserts logfire__all__.remove(member) assert hasattr(logfire_api, 'shutdown') From e2f74ef7aeb4ab64ac749b2d03d863e460f44413 Mon Sep 17 00:00:00 2001 From: sydney-runkle Date: Fri, 18 Oct 2024 13:56:10 +0100 Subject: [PATCH 26/26] my final attempt at a fix --- tests/test_logfire_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_logfire_api.py b/tests/test_logfire_api.py index aa8c31cfb..cbe9aae27 100644 --- a/tests/test_logfire_api.py +++ b/tests/test_logfire_api.py @@ -140,7 +140,7 @@ def func() -> None: ... for member in [m for m in logfire__all__ if m.startswith('instrument_')]: assert hasattr(logfire_api, member), member - if get_version(pydantic_version) >= get_version('2.5.0') and member == 'instrument_pydantic': + if not (get_version(pydantic_version) < get_version('2.5.0') and member == 'instrument_pydantic'): # skip pydantic instrumentation (which uses the plugin) for versions prior to v2.5 getattr(logfire_api, member)() # just remove the member unconditionally to pass future asserts