Skip to content

Commit

Permalink
Factor out a method to fetch type information
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Mar 10, 2015
1 parent 3431d24 commit 0f422eb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions postgres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ def parse(self, s, curs, retry=False):
tokens = self.tokenize(s)
if len(tokens) != len(self.atttypes):
# The number of columns has changed, re-fetch the type info
self.__dict__.update(self._from_db(self.name, curs).__dict__)
self._refetch_type_info(curs)

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

return self.make(values)
Expand All @@ -864,6 +864,12 @@ def make(self, values):
instance = ModelSubclass(record)
return instance

def _refetch_type_info(self, curs):
"""Given a cursor, update the current object with a fresh type definition.
"""
new_self = self._from_db(self.name, curs)
self.__dict__.update(new_self.__dict__)

return DelegatingCaster


Expand Down

0 comments on commit 0f422eb

Please sign in to comment.