Skip to content

Commit d8f59b0

Browse files
committed
Removed assertions that were hiding exceptions
The two assertions that were testing the sqlalchemy classes and instances worked by catching and silencing exceptions. This could cause debugging problems like: #121 #122 on the other hand without them, if someone uses unmapped class/model it would be trivial to diagnose the problem. So I believe we would be better off without them.
1 parent c89cf80 commit d8f59b0

File tree

2 files changed

+1
-29
lines changed

2 files changed

+1
-29
lines changed

graphene_sqlalchemy/types.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
sort_enum_for_object_type)
2222
from .fields import default_connection_field_factory
2323
from .registry import Registry, get_global_registry
24-
from .utils import get_query, is_mapped_class, is_mapped_instance
24+
from .utils import get_query
2525

2626

2727
class ORMField(OrderedType):
@@ -199,10 +199,6 @@ def __init_subclass_with_meta__(
199199
_meta=None,
200200
**options
201201
):
202-
assert is_mapped_class(model), (
203-
"You need to pass a valid SQLAlchemy Model in " '{}.Meta, received "{}".'
204-
).format(cls.__name__, model)
205-
206202
if not registry:
207203
registry = get_global_registry()
208204

@@ -271,8 +267,6 @@ def __init_subclass_with_meta__(
271267
def is_type_of(cls, root, info):
272268
if isinstance(root, cls):
273269
return True
274-
if not is_mapped_instance(root):
275-
raise Exception(('Received incompatible instance "{}".').format(root))
276270
return isinstance(root, cls._meta.model)
277271

278272
@classmethod

graphene_sqlalchemy/utils.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import re
22
import warnings
33

4-
from sqlalchemy.exc import ArgumentError
5-
from sqlalchemy.orm import class_mapper, object_mapper
6-
from sqlalchemy.orm.exc import UnmappedClassError, UnmappedInstanceError
7-
84

95
def get_session(context):
106
return context.get("session")
@@ -23,24 +19,6 @@ def get_query(model, context):
2319
return query
2420

2521

26-
def is_mapped_class(cls):
27-
try:
28-
class_mapper(cls)
29-
except (ArgumentError, UnmappedClassError):
30-
return False
31-
else:
32-
return True
33-
34-
35-
def is_mapped_instance(cls):
36-
try:
37-
object_mapper(cls)
38-
except (ArgumentError, UnmappedInstanceError):
39-
return False
40-
else:
41-
return True
42-
43-
4422
def to_type_name(name):
4523
"""Convert the given name to a GraphQL type name."""
4624
return "".join(part[:1].upper() + part[1:] for part in name.split("_"))

0 commit comments

Comments
 (0)