edgedb icon indicating copy to clipboard operation
edgedb copied to clipboard

Unexpected `InvalidReferenceError` in rewrite update expression

Open devlzcode opened this issue 1 year ago • 0 comments

  • EdgeDB Version: EdgeDB 5.3+a480d96
  • EdgeDB CLI Version: EdgeDB CLI 5.1.0+8ff9f85
  • OS Version: macOS 14.4

Steps to Reproduce:

  1. Run edgedb migration create with the schema.

Schema:

module default {
    type User  {
        required name: str;
    };

    type Item {
        required name: str;
    };

    type UserItem {
        required status: str;
        status_last_updated_at: datetime {
            rewrite update using (
                if __specified__.status then datetime_of_statement()
                else __old__.status_last_updated_at
            )
        };
        required item: Item;
        user: User;
        user_last_updated_at: datetime {
            rewrite update using (
                if __specified__.user then datetime_of_statement()
                else __old__.user_last_updated_at
            )
        };
    };

    type Trade {
        required sender: User;
        required recipient: User;
        multi sender_item_ids: uuid;
        multi recipient_item_ids: uuid;
        trigger on_insert after insert for each do (
            for i in {
                (__new__.sender, <UserItem><uuid>__new__.recipient_item_ids),
                (__new__.recipient, <UserItem><uuid>__new__.sender_item_ids)
            } union (update i.1 set { user := i.0 })
        )
    };
}

InvalidReferenceError: status is not a member of tuple<__type__: std::bool, id: std::bool, item: std::bool, user: std::bool, status_last_updated_at: std::bool>

The culprit for this issue appears to be the on_insert trigger in Trade because when removed it no longer occurs. Removing status_last_updated_at will also fix the issue but is an odd behavior considering that user_last_updated_at uses the same logic. #6800 might be a similar issue, however it mentions using an extended type which I have none of.

Edit: Modifying the update clause in the trigger to include status := "test" will also fix the issue.

devlzcode avatar May 06 '24 13:05 devlzcode