Skip to content

Commit 23ef63e

Browse files
committed
Simplified instance field getter
1 parent b3dad1a commit 23ef63e

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

graphene/core/fields.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,7 @@ def resolve(self, instance, args, info):
5555
if resolve_fn:
5656
return resolve_fn(instance, args, info)
5757
else:
58-
if isinstance(instance, BaseObjectType):
59-
return instance.get_field(self.field_name)
60-
if hasattr(instance, self.field_name):
61-
return getattr(instance, self.field_name)
62-
elif hasattr(instance, self.name):
63-
return getattr(instance, self.name)
58+
return getattr(instance, self.field_name, None)
6459

6560
@memoize
6661
def get_resolve_fn(self):

graphene/core/types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __new__(cls, instance=None, **kwargs):
120120
if not kwargs:
121121
return None
122122
elif type(instance) is cls:
123-
instance = instance.instance
123+
return instance
124124

125125
return super(BaseObjectType, cls).__new__(cls)
126126

@@ -137,9 +137,6 @@ def __getattr__(self, name):
137137
if self.instance:
138138
return getattr(self.instance, name)
139139

140-
def get_field(self, field):
141-
return getattr(self.instance, field, None)
142-
143140
@classmethod
144141
def resolve_objecttype(cls, schema, instance, *_):
145142
return instance

0 commit comments

Comments
 (0)