tarantool / tarantool/tarantool
Do not force the user to pass valid tuples to `before_replace` triggers
@unera is already working on this.
Since Jan 13, 2023.
- Dominant language
- Lua
- Stars
- 3.7k
- Forks
- 419
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 88
Description
When fixing the issue #6780 it was decided^1 that before_replace triggers should receive a well formed tuple (that is, they check tuple format even before operating on it).
This behaviour change breaks one possible use case, when the user fills in the default values for some fields in before_replace triggers. The field is not nullable, and shouldn't be, but it's value might be set right in the before_replace trigger. Reported in https://jira.vk.team/browse/TNT-711.
How to reproduce:
After some preparations
tarantool> box.cfg{log_level=1}
---
...
tarantool> _ = box.schema.space.create('test', {format = {{'col1', 'unsigned'}, {'col2', 'unsigned'}}})
---
...
tarantool> _ = box.space.test:create_index('pk')
---
...
tarantool> box.space.test:before_replace(function(old, new) return new:update({{'=', 2, 100500}}) end)
---
- 'function: 0x0102c232d0'
...
I expect this to work without errors:
tarantool> box.space.test:insert{1}
---
- error: Tuple field 2 (col2) required by space format is missing
...
Like it did before 884b3ff3ffa5f6a9d4c3982611da83dc935d0b17:
tarantool> box.space.test:insert{1}
---
- [1, 100500]
...
Possible fix:
I suppose we could check only the primary key presence before and after before_replace calls, but only check the full tuple format after all before_replace triggers are fired. This would allow for a usecase when the user finishes building the tuple in before_replace triggers.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.