irtnog / lethbridge

SQLAlchemy ORM and Marshmallow schemas for Elite: Dangerous game data
GNU Affero General Public License v3.0
2 stars 0 forks source link

Error importing HIP 30377 Thargoid stronghold from test data #1

Closed xenophonf closed 9 months ago

xenophonf commented 10 months ago

I'm using a container built from efb71a1 (HEAD of main at time of writing)

> docker run -it --rm lethbridge --version
lethbridge 0.2.1, a free/libre/open source client for EDDN (and more)
Copyright (C) 2023  Matthew X. Economou
License AGPLv3+: GNU AGPL version 3 or later <https://www.gnu.org/licenses/agpl.html>.
Source code for this version can be found at <https://github.com/irtnog/lethbridge>.
> touch galaxy.sqlite
> docker run -it --rm -v `pwd`/galaxy.sqlite:/home/lethbridge/galaxy.sqlite lethbridge database upgrade head
> docker run -it --rm -v `pwd`/galaxy.sqlite:/home/lethbridge/galaxy.sqlite lethbridge database current
Current revision(s) for sqlite:///galaxy.sqlite:
Rev: a41aac16b9b4 (head)
Parent: 549d345a9779
Path: /home/lethbridge/.local/lib/python3.11/site-packages/lethbridge/migrations/versions/a41aac16b9b4_model_the_state_of_the_second_thargoid_.py

    model the state of the Second Thargoid War

    Revision ID: a41aac16b9b4
    Revises: 549d345a9779
    Create Date: 2023-07-31 19:40:07.149465+00:00

> docker run -it --rm -v `pwd`/galaxy.sqlite:/home/lethbridge/galaxy.sqlite -v `pwd`/tests/mock-galaxy-data.json:/home/lethbridge/galaxy-data.json lethbridge import spansh --fg galaxy-data.json
Importing <System(id64=1865903245675, '36 Ophiuchi')>
Importing <System(id64=92375856378, 'Eactainds QE-A c29-0')>
Importing <System(id64=19864592856314, 'Eactaips ZI-X c28-72')>
/home/lethbridge/.local/lib/python3.11/site-packages/marshmallow_sqlalchemy/load_instance_mixin.py:58: SAWarning: Object of type <FactionState> not in session, add operation along 'Faction.systems' will not proceed (This warning originated from the Session 'autoflush' process, which was invoked automatically in response to a user-initiated operation.)
  return self.session.query(self.opts.model).filter_by(**filters).first()
/home/lethbridge/.local/lib/python3.11/site-packages/marshmallow_sqlalchemy/load_instance_mixin.py:58: SAWarning: Object of type <Station> not in session, add operation along 'Faction.controlledStations' will not proceed (This warning originated from the Session 'autoflush' process, which was invoked automatically in response to a user-initiated operation.)
  return self.session.query(self.opts.model).filter_by(**filters).first()
Importing <System(id64=5069001008553, 'LHS 449')>
Importing <System(id64=7268024264113, 'Luyten 205-128')>
Importing <System(id64=178618511, 'S171 43')>
Importing <System(id64=4271084931435, 'Saktsak')>
Importing <System(id64=10477373803, 'Sol')>
Importing <System(id64=2849505885, 'x1 Centauri')>
Importing <System(id64=57149482164, 'HR 2204')>
Importing <System(id64=79247165795, 'HIP 30377')>
2023-12-17 19:57:25,784 - lethbridge.cli.import - ERROR - (sqlite3.IntegrityError) NOT NULL constraint failed: thargoid_war.successState
[SQL: INSERT INTO thargoid_war ("currentState", "successState", "failureState", progress, "daysRemaining", "portsRemaining", "successReached", system_id64) VALUES (?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: ('Thargoid Stronghold', None, None, 0.0, 0, 0, 0, 79247165795)]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
Import complete.
> sqlite3 galaxy.sqlite
SQLite version 3.37.2 2022-01-06 13:25:41
Enter ".help" for usage hints.
sqlite> .schema thargoid_war
CREATE TABLE thargoid_war (
        "currentState" VARCHAR NOT NULL,
        "successState" VARCHAR NOT NULL,
        "failureState" VARCHAR NOT NULL,
        progress NUMERIC NOT NULL,
        "daysRemaining" INTEGER NOT NULL,
        "portsRemaining" INTEGER NOT NULL,
        "successReached" BOOLEAN NOT NULL,
        system_id64 BIGINT NOT NULL,
        PRIMARY KEY (system_id64),
        FOREIGN KEY(system_id64) REFERENCES system (id64)
);
xenophonf commented 10 months ago

I got the same error using PostgreSQL:

2023-12-17 16:47:35,599 - lethbridge.cli.import - ERROR - (psycopg2cffi._impl.exceptions.IntegrityError) null value in column "successState" of relation "thargoid_war" violates not-null constraint
DETAIL:  Failing row contains (Thargoid Stronghold, null, null, 0, 0, 0, f, 79247165795).

[SQL: INSERT INTO thargoid_war ("currentState", "successState", "failureState", progress, "daysRemaining", "portsRemaining", "successReached", system_id64) VALUES (%(currentState)s, %(successState)s, %(failureState)s, %(progress)s, %(daysRemaining)s, %(portsRemaining)s, %(successReached)s, %(system_id64)s)]
[parameters: {'currentState': 'Thargoid Stronghold', 'successState': None, 'failureState': None, 'progress': Decimal('0'), 'daysRemaining': 0, 'portsRemaining': 0, 'successReached': False, 'system_id64': 79247165795}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)

Again, the table has NOT NULL constraints when it shouldn't:

lethbridge=# \d thargoid_war
                     Table "public.thargoid_war"
     Column     |       Type        | Collation | Nullable | Default
----------------+-------------------+-----------+----------+---------
 currentState   | character varying |           | not null |
 successState   | character varying |           | not null |
 failureState   | character varying |           | not null |
 progress       | numeric           |           | not null |
 daysRemaining  | integer           |           | not null |
 portsRemaining | integer           |           | not null |
 successReached | boolean           |           | not null |
 system_id64    | bigint            |           | not null |
Indexes:
    "thargoid_war_pkey" PRIMARY KEY, btree (system_id64)
Foreign-key constraints:
    "thargoid_war_system_id64_fkey" FOREIGN KEY (system_id64) REFERENCES system(id64)
xenophonf commented 9 months ago

Fixed in commit fa5d008f498b2653ae22af27c87a268a1d882c29.