'validates' include_removes=True doesn't seem to prevent deletion?

6 views
Skip to first unread message

niuji...@gmail.com

unread,
Oct 4, 2021, 9:50:00 PMOct 4
to sqlalchemy
I have the following validator:

    @sa_orm.validates('variant_names', include_removes=True)
    def validate_unique_identifying(self, key, name_dict,
                                    is_remove):
        if is_remove:
            raise ValueError("DOn't")
        else:
            if name_dict.is_primary_identifying_flag is None:
                name_dict.is_primary_identifying_flag = False
            return name_dict


When deleting, I get the raised ValueError, but the deletion occured anyway.
Is this the expected behaviour? Or there is some other settings that can prevent the deletion?

Mike Bayer

unread,
Oct 5, 2021, 9:45:18 AMOct 5
to noreply-spamdigest via sqlalchemy


On Mon, Oct 4, 2021, at 9:49 PM, niuji...@gmail.com wrote:
I have the following validator:

    @sa_orm.validates('variant_names', include_removes=True)
    def validate_unique_identifying(self, key, name_dict,
                                    is_remove):
        if is_remove:
            raise ValueError("DOn't")
        else:
            if name_dict.is_primary_identifying_flag is None:
                name_dict.is_primary_identifying_flag = False
            return name_dict


When deleting, I get the raised ValueError, but the deletion occured anyway.
Is this the expected behaviour? 

not as of SQLAlchemy 1.3, nope.   valueerror will prevent removal from a collection assuming you are using list.remove() or set.remove().  may not work for pop().




Or there is some other settings that can prevent the deletion?


--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages