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

При переносе карточки от одного юзера другому ломается синхронизация баз #10

Open
jekhor opened this issue Oct 12, 2021 · 2 comments

Comments

@jekhor
Copy link
Member

jekhor commented Oct 12, 2021

Если на сайте ID карточки у одного пользователя удалили, а другому сразу же его добавили, то при синхронизации может возникнуть ошибка, связанная с валидацией уникальности карт:

root@bramnik:/srv/Bramnik/software/host# ./run_sync.sh 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 20523    0 20523    0     0  16362      0 --:--:--  0:00:01 --:--:-- 16379
Traceback (most recent call last):
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 6741, in get
    return clone.execute(database)[0]
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 4184, in __getitem__
    return self.row_cache[item]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 6360, in get_or_create
    return query.get(), False
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 6746, in get
    (clone.model, sql, params))
models.CardDoesNotExist: <Model: Card> instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."user_id", "t1"."card_id" FROM "cards" AS "t1" WHERE (("t1"."user_id" = ?) AND ("t1"."card_id" = ?)) LIMIT ? OFFSET ?
Params: [23, '2c4aae9c', 1, 0]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bramnik_mgr.py", line 170, in <module>
    main()
  File "bramnik_mgr.py", line 166, in main
    cli()
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "bramnik_mgr.py", line 58, in sync
    card, created = Card.get_or_create(user_id=user.id, card_id=sanitized_key)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 6362, in get_or_create
    raise exc
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 6357, in get_or_create
    return cls.create(**kwargs), True
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 6235, in create
    inst.save(force_insert=True)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 6433, in save
    pk = self.insert(**field_dict).execute()
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 1845, in inner
    return method(self, database, *args, **kwargs)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 1916, in execute
    return self._execute(database)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 2665, in _execute
    return super(Insert, self)._execute(database)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 2400, in _execute
    cursor = database.execute(self)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 3070, in execute
    return self.execute_sql(sql, params, commit=commit)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 3064, in execute_sql
    self.commit()
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 2831, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 183, in reraise
    raise value.with_traceback(tb)
  File "/srv/Bramnik/software/host/env/lib/python3.7/site-packages/peewee.py", line 3057, in execute_sql
    cursor.execute(sql, params or ())
peewee.IntegrityError: UNIQUE constraint failed: cards.card_id
@abitrolly
Copy link
Member

Надо пояснить. Одна база в RPi на брамнике, а вторая - это база с сайта https://hackerspace.by ?

@abitrolly
Copy link
Member

Ну карочи он использует закрытый API https://hackerspace.by/bramnik и я не могу посмотреть структуру записей, чтобы узнать можно ли юзать table.thaw() http://docs.peewee-orm.com/en/latest/peewee/playhouse.html

jekhor added a commit that referenced this issue Nov 27, 2021
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

No branches or pull requests

2 participants