Skip to content

Commit 4dc638b

Browse files
committed
SA RemovedIn20Warning
1 parent 65c8cb8 commit 4dc638b

8 files changed

Lines changed: 38 additions & 22 deletions

File tree

c2corg_api/models/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class User(Base):
7070
primary_key=True)
7171
profile = relationship(
7272
UserProfile, primaryjoin=id == UserProfile.document_id, uselist=False,
73-
backref=backref('user', uselist=False))
73+
backref=backref('user', uselist=False, cascade_backrefs=False))
7474

7575
username = Column(String(200), nullable=False, unique=True)
7676
name = Column(String(200), nullable=False)

c2corg_api/tests/views/test_document_schema.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55

66
class TestGetDocumentsConfig(BaseTestRest):
77

8+
@staticmethod
9+
def _field_names(fields):
10+
return [f.key for f in fields]
11+
812
def test_get_load_only_fields_routes(self):
9-
fields = route_documents_config.get_load_only_fields()
13+
fields = self._field_names(
14+
route_documents_config.get_load_only_fields())
1015
self.assertIn('elevation_max', fields)
1116
self.assertIn('ski_rating', fields)
1217
self.assertIn('rock_free_rating', fields)
@@ -20,32 +25,37 @@ def test_get_load_only_fields_routes(self):
2025
self.assertNotIn('title', fields)
2126

2227
def test_get_load_only_fields_locales_routes(self):
23-
fields = route_documents_config.get_load_only_fields_locales()
28+
fields = self._field_names(
29+
route_documents_config.get_load_only_fields_locales())
2430
self.assertIn('title', fields)
2531
self.assertIn('title_prefix', fields)
2632
self.assertIn('summary', fields)
2733
self.assertNotIn('description', fields)
2834
self.assertNotIn('gear', fields)
2935

3036
def test_get_load_only_fields_geometry_routes(self):
31-
fields = route_documents_config.get_load_only_fields_geometry()
37+
fields = self._field_names(
38+
route_documents_config.get_load_only_fields_geometry())
3239
self.assertIn('geom', fields)
3340
self.assertNotIn('geom_detail', fields)
3441

3542
def test_get_load_only_fields_topo_map(self):
36-
fields = topo_map_documents_config.get_load_only_fields()
43+
fields = self._field_names(
44+
topo_map_documents_config.get_load_only_fields())
3745
self.assertIn('code', fields)
3846
self.assertIn('editor', fields)
3947
self.assertNotIn('scale', fields)
4048
self.assertNotIn('lift_access', fields)
4149

4250
def test_get_load_only_fields_locales_topo_map(self):
43-
fields = topo_map_documents_config.get_load_only_fields_locales()
51+
fields = self._field_names(
52+
topo_map_documents_config.get_load_only_fields_locales())
4453
self.assertIn('title', fields)
4554
self.assertNotIn('summary', fields)
4655
self.assertNotIn('description', fields)
4756

4857
def test_get_load_only_fields_geometry_topo_map(self):
49-
fields = topo_map_documents_config.get_load_only_fields_geometry()
58+
fields = self._field_names(
59+
topo_map_documents_config.get_load_only_fields_geometry())
5060
self.assertNotIn('geom', fields)
5161
self.assertNotIn('geom_detail', fields)

c2corg_api/views/document_associations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,4 @@ def get_linked_xreports(document, lang):
302302

303303

304304
def get_first_column(rows):
305-
return [r for (r, ) in rows]
305+
return [r[0] for r in rows]

c2corg_api/views/document_schemas.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from c2corg_api.models.common.fields_topo_map import fields_topo_map
3131
from c2corg_api.models.common.fields_user_profile import fields_user_profile
3232
from c2corg_api.models.common.fields_coverage import fields_coverage
33+
from c2corg_api.models.document import DocumentLocale, DocumentGeometry
3334
from functools import lru_cache
3435

3536

@@ -78,22 +79,26 @@ def _collect_listing_fields(self, fields):
7879
return listing_fields
7980

8081
def get_load_only_fields(self):
81-
""" Return the fields for a document type that are needed to query
82-
documents for the listing views.
82+
""" Return SQLAlchemy class-bound attributes for document fields that
83+
are needed to query documents for the listing views. These attributes
84+
can be used directly with SQLAlchemy's load_only() option.
8385
"""
84-
return self.fields_document
86+
return [getattr(self.clazz, f) for f in self.fields_document]
8587

8688
def get_load_only_fields_locales(self):
87-
""" Return the locales fields for a document type that are needed to
88-
query documents for the listing views.
89+
""" Return SQLAlchemy class-bound attributes for locale fields that
90+
are needed to query documents for the listing views. These attributes
91+
can be used directly with SQLAlchemy's load_only() option.
8992
"""
90-
return self.fields_locales
93+
locale_clazz = self.clazz_locale or DocumentLocale
94+
return [getattr(locale_clazz, f) for f in self.fields_locales]
9195

9296
def get_load_only_fields_geometry(self):
93-
""" Return the geometry fields for a document type that are needed to
94-
query documents for the listing views.
97+
""" Return SQLAlchemy class-bound attributes for geometry fields
98+
that are needed to query documents for the listing views. These
99+
attributes can be used directly with SQLAlchemy's load_only() option.
95100
"""
96-
return self.fields_geometry
101+
return [getattr(DocumentGeometry, f) for f in self.fields_geometry]
97102

98103

99104
def make_schema_adaptor(adapt_schema_for_type, type_field, field_list_type):

c2corg_api/views/feed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def get_changes_of_personal_feed(
162162
user_id, token_id, token_time, limit, ignore_admin_changes_filter):
163163
user = DBSession.query(User). \
164164
filter(User.id == user_id). \
165-
options(undefer('has_area_filter')). \
166-
options(undefer('is_following_users')). \
165+
options(undefer(User.has_area_filter)). \
166+
options(undefer(User.is_following_users)). \
167167
first()
168168

169169
if has_no_custom_filter(user):

c2corg_api/views/route.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def set_recent_outings(route, lang):
148148
"""Set last 10 outings on the given route.
149149
"""
150150
recent_outing_ids = get_first_column(
151-
DBSession.query(Outing.document_id).
151+
DBSession.query(Outing.document_id, Outing.date_end).
152152
filter(Outing.redirects_to.is_(None)).
153153
join(
154154
Association,

c2corg_api/views/waypoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def set_recent_outings(waypoint, lang):
266266
with_query_waypoints = _get_select_children(waypoint)
267267

268268
recent_outing_ids = get_first_column(
269-
DBSession.query(Outing.document_id).
269+
DBSession.query(Outing.document_id, Outing.date_end).
270270
filter(Outing.redirects_to.is_(None)).
271271
join(
272272
t_outing_route,

pytest.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
addopts = --cov=c2corg_api
33
filterwarnings =
44
default
5+
ignore::DeprecationWarning:pkg_resources
56
ignore:pkg_resources is deprecated:DeprecationWarning
67
ignore:Deprecated call to `pkg_resources.declare_namespace:DeprecationWarning
7-
ignore:HTTPResponse.getheaders\(\) is deprecated:DeprecationWarning
8+
ignore:HTTPResponse.getheaders:DeprecationWarning:elasticsearch

0 commit comments

Comments
 (0)