From 2a76d85669d940602b4edc68cd13172250d8b297 Mon Sep 17 00:00:00 2001 From: Jason Lingohr Date: Wed, 4 May 2016 19:37:13 +1000 Subject: [PATCH] Expand out the doco around auto coercion and validation As per https://github.com/kvesteri/sqlalchemy-utils/issues/216 --- sqlalchemy_utils/listeners.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sqlalchemy_utils/listeners.py b/sqlalchemy_utils/listeners.py index 691578b..f2428cd 100644 --- a/sqlalchemy_utils/listeners.py +++ b/sqlalchemy_utils/listeners.py @@ -65,6 +65,14 @@ def force_auto_coercion(mapper=None): document.background_color # Color object session.commit() + A useful side-effect of this is that additional validation of data will be + done on the moment it is being assigned to model objects. For example + without auto coerction set, an invalid + :class:`sqlalchemy_utils.types.IPAddressType` (eg. ``10.0.0 255.255``) + would get through without an exception being raised. The database wouldn't + notice this (as most databases don't have a native type for an IP address, + so they're usually just stored as a string), and the ``ipaddress/ipaddr`` + package uses a string field as well. :param mapper: The mapper which the automatic data type coercion should be applied to