Skip to content

Commit

Permalink
fix(babel): pass validation if babel is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Veuiller committed Jul 16, 2018
1 parent 70f4710 commit 634e26f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion sqlalchemy_utils/primitives/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class Country(object):
Country(Country('FI')).code # 'FI'
Country always validates the given code.
Country always validates the given code if you use at least the optional
dependency list 'babel', otherwise no validation are performed.
::
Expand Down Expand Up @@ -76,6 +77,9 @@ def validate(self, code):
raise ValueError(
'Could not convert string to country code: {0}'.format(code)
)
except AttributeError:
# As babel is optional, we may raise an AttributeError accessing it
pass

def __eq__(self, other):
if isinstance(other, Country):
Expand Down
6 changes: 5 additions & 1 deletion sqlalchemy_utils/primitives/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class Currency(object):
Currency(Currency('USD')).code # 'USD'
Currency always validates the given code.
Currency always validates the given code if you use at least the optional
dependency list 'babel', otherwise no validation are performed.
::
Expand Down Expand Up @@ -75,6 +76,9 @@ def validate(self, code):
i18n.babel.Locale('en').currencies[code]
except KeyError:
raise ValueError("'{0}' is not valid currency code.".format(code))
except AttributeError:
# As babel is optional, we may raise an AttributeError accessing it
pass

@property
def symbol(self):
Expand Down

0 comments on commit 634e26f

Please sign in to comment.