From 980df3a08954017264ac6e252dca86e31c50c9f0 Mon Sep 17 00:00:00 2001 From: Dan Yishai Date: Tue, 15 Apr 2025 21:19:54 +0300 Subject: [PATCH 1/4] Fixed pydantic import --- permit/exceptions.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/permit/exceptions.py b/permit/exceptions.py index ec42310..d07c251 100644 --- a/permit/exceptions.py +++ b/permit/exceptions.py @@ -3,10 +3,16 @@ import aiohttp from loguru import logger -from pydantic.v1 import ValidationError from typing_extensions import deprecated -from permit import ErrorDetails, HTTPValidationError +from permit.utils.pydantic_version import PYDANTIC_VERSION + +if PYDANTIC_VERSION < (2, 0): + from pydantic.v1 import ValidationError +else: + from pydantic import ValidationError # type: ignore + +from permit.api.models import ErrorDetails, HTTPValidationError DEFAULT_SUPPORT_LINK = "https://permit-io.slack.com/ssb/redirect" From c3936944a7220c43d45d80a8cf0d52484c6ce399 Mon Sep 17 00:00:00 2001 From: Dan Yishai Date: Tue, 15 Apr 2025 21:30:13 +0300 Subject: [PATCH 2/4] Added pydantic v1/v2 matrix to Tests CI --- .github/workflows/test.yml | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cdec814..2aeac17 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,11 @@ env: jobs: pytest: runs-on: ubuntu-latest - name: pytest + strategy: + fail-fast: false + matrix: + pydantic-version: ['pydantic<2.0.0', 'pydantic>=2.0.0'] + name: pytest (Pydantic ${{ matrix.pydantic-version }}) services: pdp: image: permitio/pdp-v2:latest @@ -34,23 +38,27 @@ jobs: with: python-version: '3.11.8' - - name: Creation env ${{ env.ENV_NAME }} under 'Permit.io Tests' workspace + - name: Creation env ${{ env.ENV_NAME }}-${{ github.run_id }}-${{ matrix.pydantic-version }} + id: create_env run: | + ENV_KEY="${{ env.ENV_NAME }}-${{ github.run_id }}-${{ matrix.pydantic-version == 'pydantic<2.0.0' && 'v1' || 'v2' }}" + echo "ENV_KEY=$ENV_KEY" >> $GITHUB_ENV + response=$(curl -X POST \ https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs \ -H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}' \ -H 'Content-Type: application/json' \ -d '{ - "key": "${{ env.ENV_NAME }}", - "name": "${{ env.ENV_NAME }}" + "key": "'"$ENV_KEY"'", + "name": "'"$ENV_KEY"'" }') # Extract the new env id echo "ENV_ID=$(echo "$response" | jq -r '.id')" >> $GITHUB_ENV - echo "New env ID: $ENV_ID" + echo "New env ID: $ENV_ID with key: $ENV_KEY" - - name: Fetch API_KEY of ${{ env.ENV_NAME }} + - name: Fetch API_KEY of ${{ env.ENV_KEY }} run: | response=$(curl -X GET \ https://api.permit.io/v2/api-key/${{ env.PROJECT_ID }}/${{ env.ENV_ID }} \ @@ -61,6 +69,18 @@ jobs: echo "New env api key: $ENV_API_KEY" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest pytest-cov + # Pin pydantic version according to matrix + pip install "${{ matrix.pydantic-version }}" + if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi + if [ -f requirements.txt ]; then pip install -r requirements.txt --no-deps; fi + + - name: Show installed packages + run: pip list + - name: Test with pytest env: PDP_URL: http://localhost:7766 @@ -69,13 +89,9 @@ jobs: PROJECT_PDP_API_KEY: ${{ env.ENV_API_KEY }} PDP_API_KEY: ${{ env.ENV_API_KEY }} run: | - python -m pip install --upgrade pip - pip install flake8 pytest pytest-cov - if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi pytest -s --cache-clear tests/ - - name: Delete env ${{ env.ENV_NAME }} + - name: Delete env ${{ env.ENV_KEY }} if: always() run: | curl -X DELETE \ From 4c3638523f1753eb1102e4b53dea0eb69da537d2 Mon Sep 17 00:00:00 2001 From: Dan Yishai Date: Tue, 15 Apr 2025 21:39:28 +0300 Subject: [PATCH 3/4] Added explicitly `email-validator` --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2aeac17..22aaad4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -75,6 +75,8 @@ jobs: pip install flake8 pytest pytest-cov # Pin pydantic version according to matrix pip install "${{ matrix.pydantic-version }}" + # Explicitly install email-validator which is required for Pydantic email validation + pip install email-validator if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi if [ -f requirements.txt ]; then pip install -r requirements.txt --no-deps; fi From 4d6eebfba90d09951ef4bd7fac82781903edf6c1 Mon Sep 17 00:00:00 2001 From: Dan Yishai Date: Wed, 16 Apr 2025 12:53:07 +0300 Subject: [PATCH 4/4] Updated pre-commit CI --- .github/workflows/pre-commit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 1e3563a..7a692c2 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -9,6 +9,6 @@ jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: pre-commit/action@v2.0.3 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - uses: pre-commit/action@v3.0.1