<p dir="auto"><strong>Describe your question</strong><br>
Hi,</p>
<p dir="auto">I've missed the ability to add IGNORE to the INSERT statement when doing bulk updates. So far I've extracted necessary pieces to make this work locally, but I was wondering if this is something that is welcomed in sqlalchemy. If that is the case I would PR this feature.<br>
<strong>Example (if applicable)</strong><br>
bulk_save_objects(....,ignore_error=True)<br>
(also for bulk version of update, insert)</p>
<p dir="auto"><strong>Additional context</strong></p>
<p dir="auto"><strong>Useful links</strong><br>
<a href="https://stackoverflow.com/questions/1282025/bulk-insert-mysql-can-i-use-ignore-clause-is-there-a-limit-to-no-of-records#:~:text=Yes%2C%20you%20can%20use%20the,is%20a%20primary%20key)%3A" rel="nofollow">https://stackoverflow.com/questions/1282025/bulk-insert-mysql-can-i-use-ignore-clause-is-there-a-limit-to-no-of-records#:~:text=Yes%2C%20you%20can%20use%20the,is%20a%20primary%20key)%3A</a></p>
<p dir="auto"><strong>Have a nice day!</strong></p>
<p dir="auto"><strong>Migrated issue, originally created by zoomorph (<a href="https://github.com/zoomorph">@zoomorph</a>)</strong></p>
<p dir="auto">Listening for changes to a scalar attribute can be done via the 'set' event:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="def validate_phone(target, value, oldvalue, initiator):
    &quot;&quot;&quot;Strip non-numeric characters from a phone number&quot;&quot;&quot;

    return re.sub(r'(?![0-9])', '', value)

# setup listener on UserContact.phone attribute, instructing
# it to use the return value
listen(UserContact.phone, 'set', validate_phone, retval=True)"><pre class="notranslate"><code class="notranslate">def validate_phone(target, value, oldvalue, initiator):
    """Strip non-numeric characters from a phone number"""

    return re.sub(r'(?![0-9])', '', value)

# setup listener on UserContact.phone attribute, instructing
# it to use the return value
listen(UserContact.phone, 'set', validate_phone, retval=True)
</code></pre></div>
<p dir="auto">When Mutable attributes are set, they also emit the 'set' event. However, they do not emit any events when they are merely changed.</p>
<p dir="auto">A new event such as 'changed' should be added to cover this case. It would work like so:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="def favorites_changed(target, value, oldvalue, initiator):
    logger.info(&quot;Favorites was set or changed&quot;)
    # do something

# setup listeners on UserContact.favorites attribute (a MutableList for example)
listen(UserContact.favorites, 'set', favorites_changed)
listen(UserContact.favorites, 'changed', favorites_changed)

u = session.query(UserContact).first()
u.favorites = [1, 2, 3]  # emits 'set'
u.favorites.append(4)  # should emit 'changed'
u.favorites[-1] = 5  # should emit 'changed'"><pre class="notranslate"><code class="notranslate">def favorites_changed(target, value, oldvalue, initiator):
    logger.info("Favorites was set or changed")
    # do something

# setup listeners on UserContact.favorites attribute (a MutableList for example)
listen(UserContact.favorites, 'set', favorites_changed)
listen(UserContact.favorites, 'changed', favorites_changed)

u = session.query(UserContact).first()
u.favorites = [1, 2, 3]  # emits 'set'
u.favorites.append(4)  # should emit 'changed'
u.favorites[-1] = 5  # should emit 'changed'
</code></pre></div>
<p dir="auto">Related to issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="384632812" data-permission-text="Title is private" data-url="https://github.com/sqlalchemy/sqlalchemy/issues/3297" data-hovercard-type="issue" data-hovercard-url="/sqlalchemy/sqlalchemy/issues/3297/hovercard" href="https://github.com/sqlalchemy/sqlalchemy/issues/3297">#3297</a></p>