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

Fix sequence deletion after nextval call #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

agscpp
Copy link

@agscpp agscpp commented Sep 24, 2024

CREATE SEQUENCE serial_01 CYCLE;
SELECT nextval('serial_01');
DROP SEQUENCE serial_01;
Tarantool error: DropSequence: Can't drop sequence 'serial_01': the sequence has data

@agscpp
Copy link
Author

agscpp commented Sep 24, 2024

Hi, @gmoshkin .

Can you please take a look at my pull request?

@gmoshkin
Copy link
Contributor

Hi, thanks for the patch!

Could you explain, how are the provided SQL commands related to the test?

CREATE SEQUENCE serial_01 CYCLE;
SELECT nextval('serial_01');
DROP SEQUENCE serial_01

The code in question will not be invoked when this SQL is executed.

Could you also add a test, so that we don't break the fix accidentally in the future.

@agscpp
Copy link
Author

agscpp commented Sep 26, 2024

This is an abstract example that I used to compare the behavior with other DBMSs.

Okay, I'll write tests for this logic.

@agscpp
Copy link
Author

agscpp commented Sep 26, 2024

@gmoshkin
I wrote the tests

@gmoshkin
Copy link
Contributor

Also please update CHANGELOG.md, we try keeping it up to date with every merge we make into the master branch.

@agscpp
Copy link
Author

agscpp commented Sep 30, 2024

@gmoshkin

tests/src/box.rs Outdated
let mut seq = Sequence::find("test_drop_seq").unwrap().unwrap();
assert_eq!(seq.next().unwrap(), 1);

tarantool::schema::sequence::drop_sequence(2).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the test! There's a problem though, this hard-coded id is volatile as it may change if another test is added (if someone adds another sequence). We could make it much more robust if we got the id from the Sequence struct. Unfortunately there's currently no method for this, but it's very easy to add it.

Do you mind adding fn id(&self) -> u32 for the Sequence struct and using it in this test?

This will also be potentially useful for other users of tarantool-module as it will allow explicit deletion of sequences, by adding the ability to get the id of the instance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I wrote this comment yesterday, but failed to submit the review

Copy link
Author

@agscpp agscpp Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have corrected the code based on your comments. Please take a look again.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agscpp agscpp force-pushed the fix-drop-sequence branch from f1187e6 to b45cd7c Compare October 1, 2024 14:03
@agscpp agscpp requested a review from gmoshkin October 8, 2024 10:39
@agscpp
Copy link
Author

agscpp commented Oct 29, 2024

@gmoshkin
ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants