Skip to content

Commit 8ba28ad

Browse files
joshNisanthan Nanthakumar
josh
authored and
Nisanthan Nanthakumar
committed
feat(django): pytest startup and test collection on Django 1.11 (#16105)
1 parent c72fc6b commit 8ba28ad

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

.travis.yml

+42
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ matrix:
149149
name: 'Acceptance'
150150
env: TEST_SUITE=acceptance USE_SNUBA=1
151151

152+
# allowed to fail
153+
- <<: *postgres_default
154+
name: '[Django 1.11] Backend with migrations [Postgres] (1/2)'
155+
env: DJANGO_VERSION=">=1.11,<1.12" TEST_SUITE=postgres DB=postgres TOTAL_TEST_GROUPS=2 TEST_GROUP=0 MIGRATIONS_TEST_MIGRATE=1
156+
157+
# allowed to fail
158+
- <<: *postgres_default
159+
name: '[Django 1.11] Backend with migrations [Postgres] (2/2)'
160+
env: DJANGO_VERSION=">=1.11,<1.12" TEST_SUITE=postgres DB=postgres TOTAL_TEST_GROUPS=2 TEST_GROUP=1 MIGRATIONS_TEST_MIGRATE=1
161+
162+
# allowed to fail
163+
- <<: *acceptance_default
164+
name: '[Django 1.11] Acceptance'
165+
env: DJANGO_VERSION=">=1.11,<1.12" TEST_SUITE=acceptance USE_SNUBA=1 PERCY_ENABLE=0
166+
152167
- <<: *acceptance_default
153168
name: 'Plugins'
154169
env: TEST_SUITE=plugins DB=postgres PERCY_TOKEN=${PLUGIN_PERCY_TOKEN}
@@ -214,6 +229,29 @@ matrix:
214229
before_script:
215230
- psql -c 'create database sentry;' -U postgres
216231

232+
# allowed to fail
233+
- python: 2.7
234+
name: '[Django 1.11] Snuba Integration with migrations'
235+
env: DJANGO_VERSION=">=1.11,<1.12" TEST_SUITE=snuba USE_SNUBA=1 SENTRY_ZOOKEEPER_HOSTS=localhost:2181 SENTRY_KAFKA_HOSTS=localhost:9092 MIGRATIONS_TEST_MIGRATE=1
236+
services:
237+
- docker
238+
- memcached
239+
- redis-server
240+
- postgresql
241+
before_install:
242+
- *pip_install
243+
- docker run -d --network host --name zookeeper -e ZOOKEEPER_CLIENT_PORT=2181 confluentinc/cp-zookeeper:4.1.0
244+
- docker run -d --network host --name kafka -e KAFKA_ZOOKEEPER_CONNECT=localhost:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 confluentinc/cp-kafka:4.1.0
245+
- docker run -d --network host --name clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server:19.11
246+
- docker run -d --network host --name snuba --env SNUBA_SETTINGS=test --env CLICKHOUSE_SERVER=localhost:9000 getsentry/snuba
247+
- docker ps -a
248+
install:
249+
- python setup.py install_egg_info
250+
- pip install -U -e ".[dev]"
251+
- pip install confluent-kafka
252+
before_script:
253+
- psql -c 'create database sentry;' -U postgres
254+
217255
# Deploy 'storybook' (component & style guide) - allowed to fail
218256
- name: 'Storybook Deploy'
219257
language: node_js
@@ -235,6 +273,10 @@ matrix:
235273

236274
allow_failures:
237275
- name: 'Storybook Deploy'
276+
- name: '[Django 1.11] Backend with migrations [Postgres] (1/2)'
277+
- name: '[Django 1.11] Backend with migrations [Postgres] (2/2)'
278+
- name: '[Django 1.11] Acceptance'
279+
- name: '[Django 1.11] Snuba Integration with migrations'
238280

239281
notifications:
240282
webhooks:

src/sentry/db/postgres/base.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from six import string_types
44
import psycopg2 as Database
55

6+
import django
7+
68
# Some of these imports are unused, but they are inherited from other engines
79
# and should be available as part of the backend ``base.py`` namespace.
810
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper
@@ -95,7 +97,18 @@ def _set_isolation_level(self, level):
9597
@auto_reconnect_connection
9698
def _cursor(self, *args, **kwargs):
9799
cursor = super(DatabaseWrapper, self)._cursor()
98-
return CursorWrapper(self, cursor)
100+
if django.VERSION[:2] < (1, 11):
101+
return CursorWrapper(self, cursor)
102+
return cursor
103+
104+
# We're overriding this internal method that's present in Django 1.11+, because
105+
# things were shuffled around since 1.10 resulting in not constructing a django CursorWrapper
106+
# with our CursorWrapper. We need to be passing our wrapped cursor to their wrapped cursor,
107+
# not the other way around since then we'll lose things like __enter__ due to the way this
108+
# wrapper is working (getattr on self.cursor).
109+
def _prepare_cursor(self, cursor):
110+
cursor = super(DatabaseWrapper, self)._prepare_cursor(CursorWrapper(self, cursor))
111+
return cursor
99112

100113
def close(self, reconnect=False):
101114
"""

src/sentry/new_migrations/monkey/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from django.db.migrations import migration, executor, writer
99

10-
LAST_VERIFIED_DJANGO_VERSION = (1, 10)
10+
LAST_VERIFIED_DJANGO_VERSION = (1, 11)
1111
CHECK_MESSAGE = """Looks like you're trying to upgrade Django! Since we monkeypatch
1212
the Django migration library in several places, please verify that we have the latest
1313
code, and that the monkeypatching still works as expected. Currently the main things

src/sentry/runner/initializer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ def __model_unpickle_compat(model_id, attrs=None, factory=None):
404404
attrs = [] if attrs is None else attrs
405405
factory = django.db.models.base.simple_class_factory if factory is None else factory
406406
return model_unpickle(model_id, attrs, factory)
407-
elif VERSION[:2] == (1, 10):
407+
# TODO(joshuarli): unverified on 1.11, but i'm doing this to unblock tests for now
408+
elif VERSION[:2] in [(1, 10), (1, 11)]:
408409
return model_unpickle(model_id)
409410
else:
410411
raise NotImplementedError

0 commit comments

Comments
 (0)