Skip to content
Snippets Groups Projects
  • John Swanson's avatar
    25bab869
    Don't dissoc `:id` in `before-update` (#50375) · 25bab869
    John Swanson authored
    * Don't dissoc `:id` in `before-update`
    
    There seems to be a nasty footgun in toucan2 here.
    
    Say you're executing an `update!` command on a set of IDs, e.g.:
    
    ```
    (t2/update! :model/Card :id [:in 1 2] {:view_count 1})
    ```
    
    This works if:
    
    - both cards 1 and 2 have `view_count=1` already
    
    - both cards 1 and 2 have `view_count!=1`
    
    However.
    
    If one of the two cards has `view_count=1` and another has a different
    view_count, then (if the `before-update` method doesn't have the primary
    key attached) Toucan emits a call to update *every card in the
    database*, without a where clause at all.
    Don't dissoc `:id` in `before-update` (#50375)
    John Swanson authored
    * Don't dissoc `:id` in `before-update`
    
    There seems to be a nasty footgun in toucan2 here.
    
    Say you're executing an `update!` command on a set of IDs, e.g.:
    
    ```
    (t2/update! :model/Card :id [:in 1 2] {:view_count 1})
    ```
    
    This works if:
    
    - both cards 1 and 2 have `view_count=1` already
    
    - both cards 1 and 2 have `view_count!=1`
    
    However.
    
    If one of the two cards has `view_count=1` and another has a different
    view_count, then (if the `before-update` method doesn't have the primary
    key attached) Toucan emits a call to update *every card in the
    database*, without a where clause at all.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.