From: jonathan vanasco Date: Wed, 8 Sep 2021 18:19:24 +0000 (-0400) Subject: Fixes: #5596 X-Git-Tag: rel_1_4_24~22^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb9f86aa4f894ad706616cdd18ea68bd8618695d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fixes: #5596 replace `assert` with ValueError, as assert is optimized away by cpython Change-Id: I963ec962ee0b03935b4cda76abcf82f71274aba8 --- diff --git a/doc/build/orm/mapped_attributes.rst b/doc/build/orm/mapped_attributes.rst index 91e43d2021..a4fd3115d5 100644 --- a/doc/build/orm/mapped_attributes.rst +++ b/doc/build/orm/mapped_attributes.rst @@ -27,7 +27,8 @@ issued when the ORM is populating the object:: @validates('email') def validate_email(self, key, address): - assert '@' in address + if '@' not in address: + raise ValueError("failed simple email validation") return address .. versionchanged:: 1.0.0 - validators are no longer triggered within @@ -48,7 +49,8 @@ collection:: @validates('addresses') def validate_address(self, key, address): - assert '@' in address.email + if '@' not in address.email: + raise ValueError("failed simplified email validation") return address @@ -72,7 +74,8 @@ argument which if ``True`` indicates that the operation is a removal:: raise ValueError( "not allowed to remove items from the collection") else: - assert '@' in address.email + if '@' not in address.email: + raise ValueError("failed simplified email validation") return address The case where mutually dependent validators are linked via a backref @@ -89,7 +92,8 @@ event occurs as a result of a backref:: @validates('addresses', include_backrefs=False) def validate_address(self, key, address): - assert '@' in address.email + if '@' not in address: + raise ValueError("failed simplified email validation") return address Above, if we were to assign to ``Address.user`` as in ``some_address.user = some_user``,