Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psycopg3 changes #186

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,20 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.7', '3.8', '3.9']
python: ['3.8', '3.9', '3.10']
# Time to switch to pytest or nose2??
# nosetests is broken on 3.10
# nosetests is broken on 3.11
# AttributeError: module 'collections' has no attribute 'Callable'
# https://github.com/nose-devs/nose/issues/1099
django:
- 'Django~=3.2.0'
- 'Django~=4.0.0'
- 'Django~=4.1.0'
- 'Django~=4.2.0'
psycopg:
- 'psycopg2>2.9'
- 'psycopg>=3.1.8'
experimental: [false]
# include:
# - python: '3.9'
# django: 'https://github.com/django/django/archive/refs/heads/main.zip#egg=Django'
# experimental: true
# # NOTE this job will appear to pass even when it fails because of
# # `continue-on-error: true`. Github Actions apparently does not
# # have this feature, similar to Travis' allow-failure, yet.
# # https://github.com/actions/toolkit/issues/399
exclude:
- python: '3.7'
django: 'Django~=4.0.0'
- python: '3.7'
django: 'Django~=4.1.0'
- python: '3.7'
django: 'Django~=4.2.0'
services:
postgres:
image: postgres:latest
Expand All @@ -64,6 +52,7 @@ jobs:
pip install -r requirements/requirements.txt
pip install -r requirements/requirements-testing.txt
pip install "${{ matrix.django }}"
pip uninstall psycopg psycopg2 && pip install "${{ matrix.psycopg }}"
pip freeze
- name: Run tests
env:
Expand Down
60 changes: 45 additions & 15 deletions entity/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,25 @@ def upsert_entity_kinds(self, entity_kinds):
# Filter out unchanged entity kinds
unchanged_entity_kinds = {}
if entity_kinds:
sql_where = (
'(name, display_name) IN ('
'' + ','.join(['(%s, %s)' for _ in entity_kinds]) + ''
')'
)

sql_params = list(sum(
list(
(entity_kind.name, entity_kind.display_name)
for entity_kind in entity_kinds
),
()
))

unchanged_entity_kinds = {
(entity_kind.name, entity_kind.display_name): entity_kind
for entity_kind in EntityKind.all_objects.extra(
where=['(name, display_name) IN %s'],
params=[tuple(
(entity_kind.name, entity_kind.display_name)
for entity_kind in entity_kinds
)]
where=[sql_where],
params=sql_params
)
}

Expand Down Expand Up @@ -455,16 +466,24 @@ def upsert_entities(self, entities, sync=False):
if not sync:
select_for_update_query = (
'SELECT FROM {table_name} '
'WHERE (entity_type_id, entity_id) IN %s '
'WHERE (entity_type_id, entity_id) = ANY(ARRAY[{tuples}]) '
'ORDER BY id ASC '
'FOR NO KEY UPDATE'
).format(
table_name=Entity._meta.db_table
table_name=Entity._meta.db_table,
tuples=','.join(
['(%s, %s)' for _ in entities]
)
)
select_for_update_query_params = [tuple(
(entity.entity_type_id, entity.entity_id)
for entity in entities
)]

# Flatten a list of entity_type_id, entity_id tuples for our param replacements
select_for_update_query_params = list(sum(
list(
(entity.entity_type_id, entity.entity_id)
for entity in entities
),
()
))

# Select the items for update
with connection.cursor() as cursor:
Expand All @@ -475,12 +494,23 @@ def upsert_entities(self, entities, sync=False):
# entities that were activated or deactivated
initial_queryset = Entity.all_objects.all()
if not sync:
initial_queryset = Entity.all_objects.extra(
where=['(entity_type_id, entity_id) IN %s'],
params=[tuple(
sql_where = (
'(entity_type_id, entity_id) IN ('
'' + ','.join(['(%s, %s)' for _ in entities]) + ''
')'
)

sql_params = list(sum(
list(
(entity.entity_type_id, entity.entity_id)
for entity in entities
)]
),
()
))

initial_queryset = Entity.all_objects.extra(
where=[sql_where],
params=sql_params
)
initial_entity_activation_state = {
entity[0]: entity[1]
Expand Down
2 changes: 1 addition & 1 deletion entity/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '6.2.2'
__version__ = '6.3.0'
4 changes: 4 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env python
import sys

# These lines allow nose tests to work in Python 3.10
import collections.abc
collections.Callable = collections.abc.Callable

# Show warnings about django deprecations - uncomment for version upgrade testing
import warnings
from django.utils.deprecation import RemovedInNextVersionWarning
Expand Down
3 changes: 2 additions & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Release Notes

- 6.3.0:
- Add support for psycopg3. Still supports psycopg2.
- 6.2.2:
- Fixed entity group logic string for logic sets containing more than 2 items being operated on
- 6.2.1:
Expand Down
4 changes: 4 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from optparse import OptionParser
from settings import configure_settings

# These lines allow nose tests to work in Python 3.10
import collections.abc
collections.Callable = collections.abc.Callable

# Configure the default settings and setup django
configure_settings()

Expand Down