eveseat / seat

🌀✳️ SeAT: A Simple, EVE Online API Tool and Corporation Manager

Home Page:https://eveseat.github.io/docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicate corporation asset entry

warlof opened this issue · comments

  • Problem: Whats wrong?
./laravel-2022-01-13.log:26556:[2022-01-13 10:43:21] local.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1062
Duplicate entry '1036390695338' for key 'PRIMARY' (
SQL: insert into `corporation_assets` (`corporation_id`, `item_id`, `type_id`, `quantity`, `location_id`, `location_type`, `location_flag`, `is_singleton`, `updated_at`, `created_at`) values (***REDACTED***)
{"exception":"[object] (Illuminate\\Database\\QueryException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1036390695338' for key 'PRIMARY' (
SQL: insert into `corporation_assets` (`corporation_id`, `item_id`, `type_id`, `quantity`, `location_id`, `location_type`, `location_flag`, `is_singleton`, `updated_at`, `created_at`) values (***REDACTED***)
) at /var/www/seat/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669)
  • Expected: What did you expect to happen?
  • Logs / Screenshots / Proof: The more information you give the better!
  • Version Info: PHP Version, SeAT Version, Operating System etc.

the id is a unique key, but in the place where we query for an existing itme, there is an additional check for the corporation

This is especially weird because I believe this code is preceded with a call to wipe all of the given corporations assets, so duplicate keys shouldn't be possible.

This occurred likely as a result of the ESI failure early 2022, and was ultimately resolved by manually wiping the effected table, though a fix would be wise as I do not have an easy way to know if other corporation/character IDs have similarly corrupt data.

Issue was still extant on the following versions (but has since been manually worked around so I cannot re-test):
PHP Version: 7.4.27
SeAT API
Installed: v4.7.0
SeAT Console
Installed: v4.8.0
SeAT Eve API
Installed: v4.16.0
SeAT Notifications
Installed: v4.3.1
SeAT Services
Installed: v4.2.0
SeAT Web
Installed: v4.17.0
OS: Docker on CentOS 7 host

The file in question. Ignore my earlier comments about corporation assets wiping, that was my own misunderstanding.

https://github.com/eveseat/eveapi/blob/master/src/Jobs/Assets/Corporation/Assets.php#L112

There may be a solution in replacing firstOrNew with updateOrCreate as appropriate.

$model = CorporationAsset::updateOrCreate([
  'corporation_id' => $this->getCorporationId(),
  'item_id' => $asset->item_id,
], [
   // Map in new changed values here
]);

Or potentially adding protected static $guarded = ['item_id']; to the file below, and removing protected static $unguarded = true;

https://github.com/eveseat/eveapi/blob/master/src/Models/Assets/CorporationAsset.php#L148

To me, the issue is much tied to the table primary key (set to item_id) which is distinct from the unicity check (corporation_id + item_id)

I figure the error occurred on an item which has been transferred across corporation.

To me, the issue is much tied to the table primary key (set to item_id) which is distinct from the unicity check (corporation_id + item_id)

I figure the error occurred on an item which has been transferred across corporation.

pretty sure that is it. Is there even any reason for the corporation check?

check should match table primary key
so, actually, nope :)

To me, the issue is much tied to the table primary key (set to item_id) which is distinct from the unicity check (corporation_id + item_id)

I figure the error occurred on an item which has been transferred across corporation.

This is very possible. It occurred on one of my holding corps, and I have multiple corporations that are tracked and regularly exchange items between them.