Skip to content

Commit 5a3c843

Browse files
committed
Pick up the docstrings of hybrid properties
Use the docstring of hybrid properties as the description. Bumped build requirments for sqlalchemy becase as noted in the documentation before version 1.3.19 the ordering for all_orm_descriptors was not deterministic: ``` .. versionchanged:: 1.3.19 ensured deterministic ordering for :meth:`_orm.Mapper.all_orm_descriptors`. ``` Updated .travis.yml to match tox.ini and setup.py
1 parent 20ecaea commit 5a3c843

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

.travis.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ matrix:
1414
- env: TOXENV=py37
1515
python: 3.7
1616
dist: xenial
17-
# SQLAlchemy 1.1
18-
- env: TOXENV=py37-sql11
19-
python: 3.7
20-
dist: xenial
21-
# SQLAlchemy 1.2
22-
- env: TOXENV=py37-sql12
23-
python: 3.7
24-
dist: xenial
2517
# SQLAlchemy 1.3
2618
- env: TOXENV=py37-sql13
2719
python: 3.7

graphene_sqlalchemy/converter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def convert_sqlalchemy_hybrid_method(hybrid_prop, resolver, **field_kwargs):
114114
# TODO The default type should be dependent on the type of the property propety.
115115
field_kwargs['type'] = String
116116

117+
if 'description' not in field_kwargs:
118+
field_kwargs['description'] = getattr(hybrid_prop, "__doc__", None)
119+
117120
return Field(
118121
resolver=resolver,
119122
**field_kwargs

graphene_sqlalchemy/tests/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class Reporter(Base):
6565
articles = relationship("Article", backref="reporter")
6666
favorite_article = relationship("Article", uselist=False)
6767

68+
@hybrid_property
69+
def hybrid_prop_with_doc(self):
70+
"""Docstring test"""
71+
return self.first_name
72+
6873
@hybrid_property
6974
def hybrid_prop(self):
7075
return self.first_name

graphene_sqlalchemy/tests/test_types.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Meta:
8282
# Composite
8383
"composite_prop",
8484
# Hybrid
85+
"hybrid_prop_with_doc",
8586
"hybrid_prop",
8687
# Relationship
8788
"pets",
@@ -112,6 +113,12 @@ class Meta:
112113
# "doc" is ignored by hybrid_property
113114
assert hybrid_prop.description is None
114115

116+
# hybrid_prop_with_doc
117+
hybrid_prop_with_doc = ReporterType._meta.fields['hybrid_prop_with_doc']
118+
assert hybrid_prop_with_doc.type == String
119+
# docstring is picked up from hybrid_prop_with_doc
120+
assert hybrid_prop_with_doc.description == "Docstring test"
121+
115122
# relationship
116123
favorite_article_field = ReporterType._meta.fields['favorite_article']
117124
assert isinstance(favorite_article_field, Dynamic)
@@ -145,6 +152,7 @@ class Meta:
145152
composite_prop = ORMField()
146153

147154
# hybrid_property
155+
hybrid_prop_with_doc = ORMField(description='Overridden')
148156
hybrid_prop = ORMField(description='Overridden')
149157

150158
# relationships
@@ -172,6 +180,7 @@ class Meta:
172180
"email_v2",
173181
"column_prop",
174182
"composite_prop",
183+
"hybrid_prop_with_doc",
175184
"hybrid_prop",
176185
"favorite_article",
177186
"articles",
@@ -207,6 +216,11 @@ class Meta:
207216
assert hybrid_prop_field.description == "Overridden"
208217
assert hybrid_prop_field.deprecation_reason is None
209218

219+
hybrid_prop_with_doc_field = ReporterType._meta.fields['hybrid_prop_with_doc']
220+
assert hybrid_prop_with_doc_field.type == String
221+
assert hybrid_prop_with_doc_field.description == "Overridden"
222+
assert hybrid_prop_with_doc_field.deprecation_reason is None
223+
210224
column_prop_field_v2 = ReporterType._meta.fields['column_prop']
211225
assert column_prop_field_v2.type == String
212226
assert column_prop_field_v2.description is None
@@ -275,6 +289,7 @@ class Meta:
275289
"email",
276290
"favorite_pet_kind",
277291
"composite_prop",
292+
"hybrid_prop_with_doc",
278293
"hybrid_prop",
279294
"pets",
280295
"articles",
@@ -384,7 +399,7 @@ class Meta:
384399

385400
assert issubclass(CustomReporterType, ObjectType)
386401
assert CustomReporterType._meta.model == Reporter
387-
assert len(CustomReporterType._meta.fields) == 11
402+
assert len(CustomReporterType._meta.fields) == 12
388403

389404

390405
# Test Custom SQLAlchemyObjectType with Custom Options

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# To keep things simple, we only support newer versions of Graphene
1616
"graphene>=2.1.3,<3",
1717
"promise>=2.3",
18-
# Tests fail with 1.0.19
19-
"SQLAlchemy>=1.2,<2",
18+
# Tests fail with 1.3.18
19+
"SQLAlchemy>=1.3.19,<2",
2020
"six>=1.10.0,<2",
2121
"singledispatch>=3.4.0.3,<4",
2222
]

tox.ini

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
[tox]
2-
envlist = pre-commit,py{27,35,36,37}-sql{11,12,13}
2+
envlist = pre-commit,py{27,35,36,37}-sql13
33
skipsdist = true
44
minversion = 3.7.0
55

66
[testenv]
77
deps =
88
.[test]
9-
sql11: sqlalchemy>=1.1,<1.2
10-
sql12: sqlalchemy>=1.2,<1.3
11-
sql13: sqlalchemy>=1.3,<1.4
9+
sql13: sqlalchemy>=1.3.19,<1.4
1210
commands =
1311
pytest graphene_sqlalchemy --cov=graphene_sqlalchemy {posargs}
1412

0 commit comments

Comments
 (0)