BoostryJP / ibet-Wallet-API

A powerful API suite for seamlessly building ibet blockchain wallet systems 🛠
https://ibet.jp/ibet-for-fin
Apache License 2.0
9 stars 0 forks source link

[BUG] IntegrityError #1176

Closed YoshihitoAso closed 2 years ago

YoshihitoAso commented 2 years ago

Describe the bug

We detected the following errors in our tests This error occurs when the same token is repeatedly added and removed.

/app/ibet-Wallet-API/app/api/v2/admin.py:138: SAWarning: New instance <IDXShareToken at 0x7fa1bf6b40a0> with identity key (<class 'app.model.db.idx_token.IDXShareToken'>, ('0xdec593845c724F1cC49D7671DAdABb5914a14699',), None) conflicts with persistent instance <IDXShareToken at 0x7fa1bf81b490>
  session.commit()
2022-07-14 09:20:40 [FALCON] [ERROR] POST /v2/Admin/Tokens => Traceback (most recent call last):
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
    self.dialect.do_execute(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "share_token_pkey"
DETAIL:  Key (token_address)=(0xdec593845c724F1cC49D7671DAdABb5914a14699) already exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/falcon/app.py", line 361, in __call__
    responder(req, resp, **params)
  File "/app/ibet-Wallet-API/app/api/v2/admin.py", line 138, in on_post
    session.commit()
  File "<string>", line 2, in commit
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1451, in commit
    self._transaction.commit(_to_root=self.future)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 829, in commit
    self._prepare_impl()
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
    self.session.flush()
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3383, in flush
    self._flush(objects)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3522, in _flush
    with util.safe_reraise():
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3483, in _flush
    flush_context.execute()
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
    _emit_insert_statements(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 1097, in _emit_insert_statements
    c = connection._execute_20(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1631, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 332, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1498, in _execute_clauseelement
    ret = self._execute_context(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1862, in _execute_context
    self._handle_dbapi_exception(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2043, in _handle_dbapi_exception
    util.raise_(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 208, in raise_
    raise exception
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
    self.dialect.do_execute(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "share_token_pkey"
DETAIL:  Key (token_address)=(0xdec593845c724F1cC49D7671DAdABb5914a14699) already exists.