Skip to content

Commit 0f422eb

Browse files
committed
Factor out a method to fetch type information
1 parent 3431d24 commit 0f422eb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

postgres/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def parse(self, s, curs, retry=False):
835835
tokens = self.tokenize(s)
836836
if len(tokens) != len(self.atttypes):
837837
# The number of columns has changed, re-fetch the type info
838-
self.__dict__.update(self._from_db(self.name, curs).__dict__)
838+
self._refetch_type_info(curs)
839839

840840
try:
841841
values = [ curs.cast(oid, token)
@@ -844,7 +844,7 @@ def parse(self, s, curs, retry=False):
844844
# The type of a column has changed, re-fetch it and retry once
845845
if retry:
846846
raise
847-
self.__dict__.update(self._from_db(self.name, curs).__dict__)
847+
self._refetch_type_info(curs)
848848
return self.parse(s, curs, True)
849849

850850
return self.make(values)
@@ -864,6 +864,12 @@ def make(self, values):
864864
instance = ModelSubclass(record)
865865
return instance
866866

867+
def _refetch_type_info(self, curs):
868+
"""Given a cursor, update the current object with a fresh type definition.
869+
"""
870+
new_self = self._from_db(self.name, curs)
871+
self.__dict__.update(new_self.__dict__)
872+
867873
return DelegatingCaster
868874

869875

0 commit comments

Comments
 (0)