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

System.Sequence: inconsistency in 'number' field #45

Open
gracinet opened this Issue May 12, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@gracinet
Copy link
Contributor

gracinet commented May 12, 2018

The 'number' field contains the last used value of the sequence, which is certainly useful for applicative
code that would want to read it without incrementing it.

But this isn't true right after creation: it is in that case the first value that will be returned, unless it is 0 in which case the starting value is 1.

>>> sequence = registry.System.Sequence
>>> a = sequence.insert(code='A')
>>> a.number
0
>>> a.nextval()
'1'
>>> b = sequence.insert(code='B', number=3)
>>> b.number
3
>>> b.nextval()
'3'

>>> a.nextval()
'2'
>>> a.number
2
>>> b.nextval()
'4'
>>> b.number
4

The problem is see here is that applicative code has no way to know the correct meaning.

A cleaner way of doing would be to use two fields: start and current, and have current to be None until the first call to nextval()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.