Permalink
Browse files

In DbObject.to_map, a deep copy of the internal object is needed. Fixes

  • Loading branch information...
jmafc committed Feb 28, 2018
1 parent 72d205f commit cfc7f957c709c0e65ea3110a84b394d7f046e29e
Showing with 11 additions and 7 deletions.
  1. +2 −1 pyrseas/dbobject/__init__.py
  2. +6 −4 pyrseas/dbobject/constraint.py
  3. +3 −2 pyrseas/dbobject/table.py
@@ -332,7 +332,8 @@ def to_map(self, db, no_owner=False, no_privs=False):
The return value, a Python dictionary, is equivalent to a YAML
or JSON object.
"""
dct = self.__dict__.copy()
import copy
dct = copy.deepcopy(self.__dict__)
for key in self.keylist:
del dct[key]
if self.description is None:
@@ -483,6 +483,7 @@ def to_map(self, db, dbcols, refcols):
:param dbcols: dictionary of dbobject columns
:return: dictionary
"""
self._normalize_columns()
dct = super(ForeignKey, self).to_map(db)
if '_table' in dct:
del dct['_table']
@@ -496,14 +497,14 @@ def to_map(self, db, dbcols, refcols):
dct.pop(attr)
if self.match == 'simple':
dct.pop('match')
dct['columns'] = [dbcols[k - 1] for k in self.columns]
ref_cols = [refcols[k - 1] for k in self.ref_cols]
dct['references'] = {'table': dct['ref_table'], 'columns': ref_cols}
dct['references'] = {'table': dct['ref_table'],
'columns': self.ref_cols}
if 'ref_schema' in dct:
dct['references'].update(schema=self.ref_schema)
dct.pop('ref_schema')
dct.pop('ref_table')
dct.pop('ref_cols')

return {self.name: dct}

@commentable
@@ -573,6 +574,7 @@ def _find_referenced_index(self, db, ref_table):
return pkey

for uc in list(ref_table.unique_constraints.values()):
uc._normalize_columns()
if uc.columns == self.ref_cols:
return uc

@@ -669,6 +671,7 @@ def to_map(self, db, dbcols):
:param dbcols: dictionary of dbobject columns
:return: dictionary
"""
self._normalize_columns()
dct = super(UniqueConstraint, self).to_map(db)
if self.access_method == 'btree':
dct.pop('access_method')
@@ -677,7 +680,6 @@ def to_map(self, db, dbcols):
dct.pop(attr)
if self.tablespace is None:
dct.pop('tablespace')
dct['columns'] = [dbcols[k - 1] for k in self.columns]
return {self.name: dct}

def alter(self, inuc):
@@ -520,9 +520,10 @@ def to_map(self, db, dbschemas, opts):
if len(self.foreign_keys) > 0:
for k in list(self.foreign_keys.values()):
tbls = dbschemas[k.ref_schema].tables
tbl['foreign_keys'].update(self.foreign_keys[k.name].to_map(
ktable = self.foreign_keys[k.name]
tbl['foreign_keys'].update(ktable.to_map(
db, self.column_names(),
tbls[self.foreign_keys[k.name].ref_table].column_names()))
tbls[ktable.ref_table].column_names()))
else:
tbl.pop('foreign_keys')
if len(self.unique_constraints) > 0:

0 comments on commit cfc7f95

Please sign in to comment.