From e05b9ea79d4d51d97be624e6c5e95b6095d050cd Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Fri, 12 Feb 2016 18:59:02 -0800 Subject: [PATCH 1/3] Fixed raw_sql tracking --- graphene/contrib/django/debug/sql/tracking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene/contrib/django/debug/sql/tracking.py b/graphene/contrib/django/debug/sql/tracking.py index 00bb5c4b..47f7a30c 100644 --- a/graphene/contrib/django/debug/sql/tracking.py +++ b/graphene/contrib/django/debug/sql/tracking.py @@ -117,7 +117,7 @@ class NormalCursorWrapper(object): 'sql': self.db.ops.last_executed_query( self.cursor, sql, self._quote_params(params)), 'duration': duration, - 'raw_sql': sql % params, + 'raw_sql': sql, 'params': _params, 'start_time': start_time, 'stop_time': stop_time, From 56e1b2b6384b6f9067c34837156a5c4a6123b589 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Fri, 12 Feb 2016 18:59:17 -0800 Subject: [PATCH 2/3] Fixed default in DjangoConnection --- graphene/core/classtypes/objecttype.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/graphene/core/classtypes/objecttype.py b/graphene/core/classtypes/objecttype.py index 3f94bddf..4ae840a6 100644 --- a/graphene/core/classtypes/objecttype.py +++ b/graphene/core/classtypes/objecttype.py @@ -42,17 +42,18 @@ class ObjectTypeMeta(FieldsClassTypeMeta): class ObjectType(six.with_metaclass(ObjectTypeMeta, FieldsClassType)): + _root = None class Meta: abstract = True def __getattr__(self, name): - if name != '_root' and self._root: - return getattr(self._root, name) + print self._root + return getattr(self._root, name) def __init__(self, *args, **kwargs): - signals.pre_init.send(self.__class__, args=args, kwargs=kwargs) self._root = kwargs.pop('_root', None) + signals.pre_init.send(self.__class__, args=args, kwargs=kwargs) args_len = len(args) fields = self._meta.fields if args_len > len(fields): From e6f229ffb9a12394ce99cd6ea148e318d55db3e4 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Fri, 12 Feb 2016 19:05:34 -0800 Subject: [PATCH 3/3] Fixed django_connection defaults --- graphene/contrib/django/debug/tests/test_query.py | 4 ++-- graphene/contrib/django/fields.py | 3 +-- graphene/core/classtypes/objecttype.py | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/graphene/contrib/django/debug/tests/test_query.py b/graphene/contrib/django/debug/tests/test_query.py index c05ee799..328831b8 100644 --- a/graphene/contrib/django/debug/tests/test_query.py +++ b/graphene/contrib/django/debug/tests/test_query.py @@ -117,7 +117,7 @@ def test_should_query_connection(): class Query(graphene.ObjectType): all_reporters = DjangoConnectionField(ReporterType) - def resolve_all_reporters_connection(self, *args, **kwargs): + def resolve_all_reporters(self, *args, **kwargs): return Reporter.objects.all() query = ''' @@ -172,7 +172,7 @@ def test_should_query_connectionfilter(): class Query(graphene.ObjectType): all_reporters = DjangoFilterConnectionField(ReporterType) - def resolve_all_reporters_connection_filter(self, *args, **kwargs): + def resolve_all_reporters(self, *args, **kwargs): return Reporter.objects.all() query = ''' diff --git a/graphene/contrib/django/fields.py b/graphene/contrib/django/fields.py index d7321e21..f70e35ff 100644 --- a/graphene/contrib/django/fields.py +++ b/graphene/contrib/django/fields.py @@ -11,6 +11,7 @@ class DjangoConnectionField(ConnectionField): def __init__(self, *args, **kwargs): self.on = kwargs.pop('on', False) + kwargs['default'] = kwargs.pop('default', self.get_manager) return super(DjangoConnectionField, self).__init__(*args, **kwargs) @property @@ -27,8 +28,6 @@ class DjangoConnectionField(ConnectionField): return resolved_qs def from_list(self, connection_type, resolved, args, info): - if resolved is None: - resolved = self.get_manager() resolved_qs = maybe_queryset(resolved) qs = self.get_queryset(resolved_qs, args, info) return super(DjangoConnectionField, self).from_list(connection_type, qs, args, info) diff --git a/graphene/core/classtypes/objecttype.py b/graphene/core/classtypes/objecttype.py index 4ae840a6..e341ba97 100644 --- a/graphene/core/classtypes/objecttype.py +++ b/graphene/core/classtypes/objecttype.py @@ -42,18 +42,18 @@ class ObjectTypeMeta(FieldsClassTypeMeta): class ObjectType(six.with_metaclass(ObjectTypeMeta, FieldsClassType)): - _root = None class Meta: abstract = True def __getattr__(self, name): - print self._root + if name == '_root': + return return getattr(self._root, name) def __init__(self, *args, **kwargs): - self._root = kwargs.pop('_root', None) signals.pre_init.send(self.__class__, args=args, kwargs=kwargs) + self._root = kwargs.pop('_root', None) args_len = len(args) fields = self._meta.fields if args_len > len(fields):