Skip to content

Commit

Permalink
Fix (global.db): Consistency with updates
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <ojuswimail@gmail.com>
  • Loading branch information
OjusWiZard committed May 22, 2024
1 parent cf457d8 commit d87e347
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 4 deletions.
Binary file modified rotkehlchen/data/global.db
Binary file not shown.
9 changes: 8 additions & 1 deletion rotkehlchen/globaldb/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,14 @@ def _handle_asset_update(

try:
with connection.savepoint_ctx() as cursor:
executeall(cursor, action)
if action.strip().startswith('UPDATE') and cursor.execute(
'SELECT COUNT(*) FROM assets WHERE identifier=?',
(remote_asset_data.identifier,),
).fetchone()[0] == 0:
executeall(cursor, full_insert)
else:
executeall(cursor, action)

if local_asset is not None:
AssetResolver().clean_memory_cache(identifier=local_asset.identifier)
except sqlite3.Error: # https://docs.python.org/3/library/sqlite3.html#exceptions
Expand Down
5 changes: 5 additions & 0 deletions rotkehlchen/tests/unit/globaldb/test_asset_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
""" # noqa: E501
VALID_ASSETS = """INSERT INTO assets(identifier, name, type) VALUES("MYBONK", "Bonk", "Y"); INSERT INTO common_asset_details(identifier, symbol, coingecko, cryptocompare, forked, started, swapped_for) VALUES("MYBONK", "BONK", "bonk", "BONK", NULL, 1672279200, NULL);
*
UPDATE common_asset_details SET coingecko="coingecko-id" where identifier="new-asset";
INSERT INTO assets(identifier, name, type) VALUES("new-asset", "New Asset", "Y"); INSERT INTO common_asset_details(identifier, symbol, coingecko, cryptocompare, forked, started, swapped_for) VALUES("new-asset", "NEW", "coingecko-id", "", NULL, 1672279200, NULL);
""" # noqa: E501


Expand Down Expand Up @@ -480,6 +482,9 @@ def test_asset_update(
assert cursor.execute('SELECT * FROM assets WHERE identifier = "MYBONK"').fetchall() == ([
('MYBONK', 'Bonk', 'Y'),
] if update_assets else [])
assert cursor.execute('SELECT * FROM assets WHERE identifier = "new-asset"').fetchall() == ([
('new-asset', 'New Asset', 'Y'),
] if update_assets else [])

cursor.execute('SELECT * FROM asset_collections WHERE id = 99999999')
assert cursor.fetchall() == ([
Expand Down

0 comments on commit d87e347

Please sign in to comment.