8000 Removed assertions that were hiding exceptions by zefciu · Pull Request #238 · graphql-python/graphene-sqlalchemy · GitHub
[go: up one dir, main page]

Skip to content

Removed assertions that were hiding exceptions #238

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 1 addition & 7 deletions graphene_sqlalchemy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sort_enum_for_object_type)
from .fields import default_connection_field_factory
from .registry import Registry, get_global_registry
from .utils import get_query, is_mapped_class, is_mapped_instance
from .utils import get_query


class ORMField(OrderedType):
Expand Down Expand Up @@ -199,10 +199,6 @@ def __init_subclass_with_meta__(
_meta=None,
**options
):
assert is_mapped_class(model), (
"You need to pass a valid SQLAlchemy Model in " '{}.Meta, received "{}".'
).format(cls.__name__, model)

if not registry:
registry = get_global_registry()

Expand Down Expand Up @@ -271,8 +267,6 @@ def __init_subclass_with_meta__(
def is_type_of(cls, root, info):
if isinstance(root, cls):
return True
if not is_mapped_instance(root):
raise Exception(('Received incompatible instance "{}".').format(root))
return isinstance(root, cls._meta.model)

@classmethod
Expand Down
22 changes: 0 additions & 22 deletions graphene_sqlalchemy/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import re
import warnings

from sqlalchemy.exc import ArgumentError
from sqlalchemy.orm import class_mapper, object_mapper
from sqlalchemy.orm.exc import UnmappedClassError, UnmappedInstanceError


def get_session(context):
return context.get("session")
Expand All @@ -23,24 +19,6 @@ def get_query(model, context):
return query


def is_mapped_class(cls):
try:
class_mapper(cls)
except (ArgumentError, UnmappedClassError):
return False
else:
return True


def is_mapped_instance(cls):
try:
object_mapper(cls)
except (ArgumentError, UnmappedInstanceError):
return False
else:
return True


def to_type_name(name):
"""Convert the given name to a GraphQL type name."""
return "".join(part[:1].upper() + part[1:] for part in name.split("_"))
Expand Down
0