Skip to content

Commit

Permalink
Merge pull request #125 from dimagi/sk/strict-type
Browse files Browse the repository at this point in the history
better strict type check
  • Loading branch information
snopoke authored Aug 19, 2019
2 parents b824fdc + 0497900 commit 3c7a0cd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions commcare_export/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,14 @@ def compatible(self, source_type, dest_type):
if isinstance(source_type, _type):
return isinstance(dest_type, (_type,) + types)

def strict_types_compatibility_check(self, source_type, dest_type):
def strict_types_compatibility_check(self, source_type, dest_type, val):
if isinstance(source_type, sqlalchemy.String):
if not isinstance(dest_type, sqlalchemy.String):
return # Can't do anything
elif dest_type.length is None:
# already a TEXT column
return
return # already a TEXT column
elif dest_type.length >= len(val):
return # no need to upgrade to TEXT column
elif source_type.length is None:
return sqlalchemy.UnicodeText(collation=self.collation)
elif dest_type.length < source_type.length:
Expand Down Expand Up @@ -465,7 +466,7 @@ def get_cols():
new_type = None
if self.strict_types:
# don't bother checking compatibility since we're not going to change anything
new_type = self.strict_types_compatibility_check(ty, current_ty)
new_type = self.strict_types_compatibility_check(ty, current_ty, val)
elif not self.compatible(ty, current_ty):
new_type = self.least_upper_bound(ty, current_ty)

Expand Down

0 comments on commit 3c7a0cd

Please sign in to comment.