Issue 10235

Title
Crash trying to set sequence's number_next to zero
Priority
bug
Status
testing
Nosy list
albertca, ced, reviewbot
Assigned to
albertca
Keywords
review

Created on 2021-03-29.19:48:29 by albertca, last changed 1 week ago by ced.

Messages

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2021-03-29.23:26:19

I do not think so. This is as much arbitrary as the postgresql default. More over it still do not prevent to have similar error for out of the range value. Also database administrator could any way customize the value of a sequence.

Author: [hidden] (albertca) Tryton committer
Date: 2021-03-29.22:14:59

I think it would be better to set MINVALUE to -9223372036854775808 in:

https://hg.tryton.org/trytond/file/tip/trytond/backend/postgresql/database.py#l665

As sequence is a BIGINT by default, -9223372036854775808 is its minimum value:

https://www.postgresql.org/docs/9.1/datatype-numeric.html

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2021-03-29.20:26:12

I think a good solution would be to catch the error from the backend and raise a UserError with a proper message.

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2021-03-29.20:16:45

For me it is specificity of the backend, I do not think we should do anything against that.

Author: [hidden] (albertca) Tryton committer
Date: 2021-03-29.19:48:29

Trying to set number_next to 0 or lower will cause the following crash:

Traceback (most recent call last):
  File "/trytond/wsgi.py", line 114, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/dispatcher.py", line 48, in rpc
    request, database_name, *request.rpc_params)
  File "/trytond/wsgi.py", line 81, in auth_required
    return wrapped(*args, **kwargs)
  File "/trytond/protocols/wrappers.py", line 131, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/trytond/protocols/dispatcher.py", line 186, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/trytond/ir/sequence.py", line 184, in write
    sequence.update_sql_sequence(values.get('number_next'))
  File "/trytond/ir/sequence.py", line 264, in update_sql_sequence
    self._sql_sequence_name, self.number_increment, number_next)
  File "/trytond/backend/postgresql/database.py", line 500, in sequence_update
    (number_increment, start_value))
  File "/trytond/backend/postgresql/database.py", line 68, in execute
    cursor.execute(self, sql, args)
psycopg2.errors.InvalidParameterValue: RESTART value (0) cannot be less than MINVALUE (1)
History
Date User Action Args
2021-03-29 23:26:19cedsetmessages: + msg65926
2021-03-29 22:14:59albertcasetmessages: + msg65925
2021-03-29 20:26:12cedsetmessages: + msg65924
2021-03-29 20:18:06reviewbotsetmessages: + msg65923
nosy: + reviewbot
2021-03-29 20:16:45cedsetmessages: + msg65922
nosy: + ced
2021-03-29 19:55:46albertcasetstatus: unread -> testing
2021-03-29 19:55:34albertcasetkeyword: + review
reviews: 357601005
2021-03-29 19:48:29albertcacreate

Showing 10 items. Show all history (warning: this could be VERY long)