diff --git a/.github/workflows/test-integration-asyncpg.yml b/.github/workflows/test-integration-asyncpg.yml index 5340d40cef..0c5c124169 100644 --- a/.github/workflows/test-integration-asyncpg.yml +++ b/.github/workflows/test-integration-asyncpg.yml @@ -66,6 +66,8 @@ jobs: - name: Setup Test Env run: | pip install coverage "tox>=3,<4" + psql postgresql://postgres:sentry@localhost:5432 -c "create database ${SENTRY_PYTHON_TEST_POSTGRES_NAME};" || true + psql postgresql://postgres:sentry@localhost:5432 -c "grant all privileges on database ${SENTRY_PYTHON_TEST_POSTGRES_NAME} to ${SENTRY_PYTHON_TEST_POSTGRES_USER};" || true - name: Test asyncpg uses: nick-fields/retry@v2 diff --git a/.github/workflows/test-integration-django.yml b/.github/workflows/test-integration-django.yml index e94b138818..316b895d09 100644 --- a/.github/workflows/test-integration-django.yml +++ b/.github/workflows/test-integration-django.yml @@ -66,6 +66,8 @@ jobs: - name: Setup Test Env run: | pip install coverage "tox>=3,<4" + psql postgresql://postgres:sentry@localhost:5432 -c "create database ${SENTRY_PYTHON_TEST_POSTGRES_NAME};" || true + psql postgresql://postgres:sentry@localhost:5432 -c "grant all privileges on database ${SENTRY_PYTHON_TEST_POSTGRES_NAME} to ${SENTRY_PYTHON_TEST_POSTGRES_USER};" || true - name: Test django uses: nick-fields/retry@v2 diff --git a/scripts/split-tox-gh-actions/ci-yaml-setup-db.txt b/scripts/split-tox-gh-actions/ci-yaml-setup-db.txt new file mode 100644 index 0000000000..2dc7ab5604 --- /dev/null +++ b/scripts/split-tox-gh-actions/ci-yaml-setup-db.txt @@ -0,0 +1,2 @@ + psql postgresql://postgres:sentry@localhost:5432 -c "create database ${SENTRY_PYTHON_TEST_POSTGRES_NAME};" || true + psql postgresql://postgres:sentry@localhost:5432 -c "grant all privileges on database ${SENTRY_PYTHON_TEST_POSTGRES_NAME} to ${SENTRY_PYTHON_TEST_POSTGRES_USER};" || true diff --git a/scripts/split-tox-gh-actions/ci-yaml-test-snippet.txt b/scripts/split-tox-gh-actions/ci-yaml-test-snippet.txt index 09ed89e274..37072432d0 100644 --- a/scripts/split-tox-gh-actions/ci-yaml-test-snippet.txt +++ b/scripts/split-tox-gh-actions/ci-yaml-test-snippet.txt @@ -14,6 +14,7 @@ - name: Setup Test Env run: | pip install coverage "tox>=3,<4" + {{ setup_postgres }} - name: Test {{ framework }} uses: nick-fields/retry@v2 diff --git a/scripts/split-tox-gh-actions/split-tox-gh-actions.py b/scripts/split-tox-gh-actions/split-tox-gh-actions.py index 87759462bb..3b40178082 100755 --- a/scripts/split-tox-gh-actions/split-tox-gh-actions.py +++ b/scripts/split-tox-gh-actions/split-tox-gh-actions.py @@ -27,6 +27,7 @@ TEMPLATE_DIR = Path(__file__).resolve().parent TEMPLATE_FILE = TEMPLATE_DIR / "ci-yaml.txt" TEMPLATE_FILE_SERVICES = TEMPLATE_DIR / "ci-yaml-services.txt" +TEMPLATE_FILE_SETUP_DB = TEMPLATE_DIR / "ci-yaml-setup-db.txt" TEMPLATE_SNIPPET_TEST = TEMPLATE_DIR / "ci-yaml-test-snippet.txt" TEMPLATE_SNIPPET_TEST_PY27 = TEMPLATE_DIR / "ci-yaml-test-py27-snippet.txt" @@ -113,6 +114,11 @@ def write_yaml_file( out += "".join(lines) f.close() + elif template_line.strip() == "{{ setup_postgres }}": + if current_framework in FRAMEWORKS_NEEDING_POSTGRES: + f = open(TEMPLATE_FILE_SETUP_DB, "r") + out += "".join(f.readlines()) + elif template_line.strip() == "{{ check_needs }}": if py27_supported: out += CHECK_NEEDS_PY27 diff --git a/tests/integrations/asyncpg/test_asyncpg.py b/tests/integrations/asyncpg/test_asyncpg.py index 89dcb2595b..cfa9c32b43 100644 --- a/tests/integrations/asyncpg/test_asyncpg.py +++ b/tests/integrations/asyncpg/test_asyncpg.py @@ -33,11 +33,11 @@ CRUMBS_CONNECT = { "category": "query", "data": { - "db.name": "postgres", + "db.name": PG_NAME, "db.system": "postgresql", - "db.user": "foo", - "server.address": "localhost", - "server.port": 5432, + "db.user": PG_USER, + "server.address": PG_HOST, + "server.port": PG_PORT, }, "message": "connect", "type": "default", diff --git a/tests/integrations/django/myapp/settings.py b/tests/integrations/django/myapp/settings.py index 0d416186a0..b8b083eb81 100644 --- a/tests/integrations/django/myapp/settings.py +++ b/tests/integrations/django/myapp/settings.py @@ -121,8 +121,14 @@ def middleware(request): try: import psycopg2 # noqa + db_engine = "django.db.backends.postgresql" + try: + from django.db.backends import postgresql # noqa: F401 + except ImportError: + db_engine = "django.db.backends.postgresql_psycopg2" + DATABASES["postgres"] = { - "ENGINE": "django.db.backends.postgresql", + "ENGINE": db_engine, "NAME": os.environ["SENTRY_PYTHON_TEST_POSTGRES_NAME"], "USER": os.environ["SENTRY_PYTHON_TEST_POSTGRES_USER"], "PASSWORD": os.environ["SENTRY_PYTHON_TEST_POSTGRES_PASSWORD"], @@ -130,7 +136,9 @@ def middleware(request): "PORT": 5432, } except (ImportError, KeyError): - pass + from sentry_sdk.utils import logger + + logger.warn("No psycopg2 found, testing with SQLite.") # Password validation diff --git a/tox.ini b/tox.ini index e6f636a177..fd9a0ca5a4 100644 --- a/tox.ini +++ b/tox.ini @@ -91,7 +91,8 @@ envlist = {py3.7}-gcp # Grpc - {py3.7,py3.8,py3.9,py3.10,py3.11}-grpc-v{1.21.1,1.22.1,1.23.1,1.24.1,1.25.0,1.26.0,1.27.1,1.28.1,1.29.0,1.30.0,1.31.0,1.32.0,1.33.1,1.34.0,1.36.0,1.37.0,1.38.0,1.39.0,1.40.0,1.41.1,1.43.0,1.44.0,1.46.1,1.48.1,1.51.3,1.53.0} + {py3.7,py3.8,py3.9,py3.10}-grpc-v{1.40,1.44,1.48} + {py3.7,py3.8,py3.9,py3.10,py3.11}-grpc-v{1.54,1.56,1.58} # HTTPX {py3.6,py3.7,py3.8,py3.9}-httpx-v{0.16,0.17,0.18} @@ -248,12 +249,12 @@ deps = {py3.8}-chalice: botocore~=1.31 # Django + django: psycopg2-binary django: Werkzeug<2.1.0 django-v{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: djangorestframework>=3.0.0,<4.0.0 - {py3.7,py3.8,py3.9,py3.10,py3.11}-django-v{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: channels[daphne]>2 {py3.7,py3.8,py3.9,py3.10,py3.11}-django-v{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: pytest-asyncio - {py2.7,py3.7,py3.8,py3.9,py3.10,py3.11}-django-v{1.11,2.2,3.0,3.1,3.2}: psycopg2-binary + {py3.7,py3.8,py3.9,py3.10,py3.11}-django-v{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: channels[daphne]>2 django-v{1.8,1.9,1.10,1.11,2.0,2.1}: pytest-django<4.0 django-v{2.2,3.0,3.1,3.2}: pytest-django>=4.0 @@ -261,7 +262,6 @@ deps = django-v{4.0,4.1}: djangorestframework django-v{4.0,4.1}: pytest-asyncio - django-v{4.0,4.1}: psycopg2-binary django-v{4.0,4.1}: pytest-django django-v{4.0,4.1}: Werkzeug @@ -310,7 +310,12 @@ deps = {py2.7,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-gevent: gevent>=22.10.0, <22.11.0 # Grpc - grpc: grpcio-tools + grpc-v1.40: grpcio-tools>=1.40.0,<1.41.0 + grpc-v1.44: grpcio-tools>=1.44.0,<1.45.0 + grpc-v1.48: grpcio-tools>=1.48.0,<1.49.0 + grpc-v1.54: grpcio-tools>=1.54.0,<1.55.0 + grpc-v1.56: grpcio-tools>=1.56.0,<1.57.0 + grpc-v1.58: grpcio-tools>=1.58.0,<1.59.0 grpc: protobuf grpc: mypy-protobuf grpc: types-protobuf