Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not force the user to pass valid tuples to before_replace triggers #8155

Open
sergepetrenko opened this issue Jan 13, 2023 · 1 comment
Open
Assignees
Labels
1.10 Target is 1.10 and all newer release/master branches bug Something isn't working

Comments

@sergepetrenko
Copy link
Collaborator

sergepetrenko commented Jan 13, 2023

When fixing the issue #6780 it was decided1 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 884b3ff:

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.

Footnotes

  1. https://github.com/tarantool/tarantool/issues/6780#issuecomment-1028834339

@sergepetrenko sergepetrenko added bug Something isn't working 1.10 Target is 1.10 and all newer release/master branches labels Jan 13, 2023
@vlalykin
Copy link

vlalykin commented Feb 4, 2023

not just the default values, it could be the result of some calculations and part of complex business logic.
it's not about providing default values for space format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.10 Target is 1.10 and all newer release/master branches bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants