mtv_cli icon indicating copy to clipboard operation
mtv_cli copied to clipboard

UNIQUE constraint failed: filme._id

Open cc13com opened this issue 2 years ago • 3 comments

Since today I run in an issue when I do the update:

mtv_cli.py -A
[INFO] [2023-03-13 10:31:23] Erzeuge /home/carsten/.mediathek3/filme.sqlite aus https://liste.mediathekview.de/Filmliste-akt.xz
...........................................................[ERROR] [2023-03-13 10:31:41] Update der Filmliste gescheitert. Fehler: UNIQUE constraint failed: filme._id

Also after deleting the local filme.sqlite the same issue. Any idea?

cc13com avatar Mar 13 '23 09:03 cc13com

Thanks for the issue. I will check this (but it will take until end of this week). Maybe the format of the data-file has changed.

bablokb avatar Mar 14 '23 09:03 bablokb

As a work around I decresed the number of how many days the list should be imported in the DB. It was 180 days (without any issue until last week) and now it's 15.

cc13com avatar Mar 14 '23 09:03 cc13com

Interessting: I use 60 days and it works, so maybe there is a problem with the data-file creation which nobody noticed yet.

bablokb avatar Mar 14 '23 12:03 bablokb

Hi, I've also get exact this problem and also the workaround don't work. I've set the number to 5 Days and get this failure.

 [INFO] [2025-02-28 09:16:15] Erzeuge /home/user/.mediathek3/filme.sqlite aus https://liste.mediathekview.de/Filmliste-akt.xz
/usr/local/bin/mtv_cli.py:49: DeprecationWarning: ssl.SSLContext() without protocol argument is deprecated.
  return request.urlopen(url,context=ssl.SSLContext())
/usr/local/bin/mtv_cli.py:49: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated
  return request.urlopen(url,context=ssl.SSLContext())
[DEBUG] [2025-02-28 09:16:15] Anzahl Sätze: 12
[ERROR] [2025-02-28 09:16:15] Update der Filmliste gescheitert. Fehler: UNIQUE constraint failed: filme._id

Also you can see, the SSL info is there.

gameshacker avatar Feb 28 '25 09:02 gameshacker

Thanks. I am running this every evening and since yesterday it fails. I will need to check why. And I will have to update my scripts so that I will be alarmed.

I also have a fix for the SSL message, but I forgot to publish it.

bablokb avatar Feb 28 '25 09:02 bablokb

Good to see that the development is in progress and not EOL. :-)

cc13com avatar Feb 28 '25 11:02 cc13com

It seems they have changed the format of the film-list. There is no more _id field. Not sure if this is an error (we had that before). Too bad that I did not keep an old film-list to check.

I will see what I can do about that. Maybe I just auto-create the field.

bablokb avatar Mar 01 '25 08:03 bablokb

Hello @bablokb, I can check in one of my VMs if I will find an old film-list. Let me know if you need help.

cc13com avatar Mar 03 '25 07:03 cc13com

for me adding or replace to https://github.com/bablokb/mtv_cli/blob/deb3d3980cdb5cc7fe5ffde0eff25c2f1452b027/files/usr/local/bin/mtv_filmdb.py#L132 fixed it

magcode avatar Mar 03 '25 07:03 magcode

@cc13com

Hello @bablokb, I can check in one of my VMs if I will find an old film-list. Let me know if you need help.

That would be great. I don't need the complete filmlist. Just unpack it and post the first 256-1024 chars. It is some sort of json and one very large string but the header is upfront and I would only need the header and maybe one additional line.

bablokb avatar Mar 03 '25 15:03 bablokb

for me adding or replace to

mtv_cli/files/usr/local/bin/mtv_filmdb.py

Line 132 in deb3d39 INSERT_STMT = 'INSERT INTO filme VALUES (' + 20 * '?,' + '?)' fixed it

@magcode have you checked the filmdb after insert? I would guess that it only contains a single line. The _id field is missing and that is the key, so every record the script adds has the same empty key (a special feature of sqlite).

Nevertheless, I will probably add the or replace when I create my own _id (probably a hash from sender, thema, titel, dauer, datum). This should guard against duplicate entries. Hopefully I will have new code tomorrow.

bablokb avatar Mar 03 '25 16:03 bablokb

The issue for me was not a missing id but the same ID coming again. I did simply print out the id and called mtv_cli.py -A. Then I saw the same ID (4aef1a0c0c1d25c4ca3ef172346a63e7 coming again and the script stopped.

a2acd544ed3c2b5827bb631c48f660d1
4aef1a0c0c1d25c4ca3ef172346a63e7
2dc493cbd3b98cb15aea8ed9fa09bc73
aeb404217a7e106ca50bc1f65d635ac4
4aef1a0c0c1d25c4ca3ef172346a63e7
[ERROR] [2025-03-03 17:35:17] Update der Filmliste gescheitert. Fehler: UNIQUE constraint failed: filme._id

magcode avatar Mar 03 '25 16:03 magcode

Thanks, this helps. Actually I am a bit embarrassed, because if I look at my code I can see that I added this feature (create _id if it does not exist) already back in 2017. Totally forgot about that.

So this now boils down to check if the hash-function is not good enough or if we indeed just have duplicate lines in the filmlist. If so, your fix does the trick.

bablokb avatar Mar 03 '25 18:03 bablokb

Please download, install and test the code in the 'next' branch. This should also fix #22. If this also works for you, I will merge it to main.

bablokb avatar Mar 04 '25 08:03 bablokb

Hallo, thanks the next branch version works without failure.

[INFO] [2025-03-04 09:09:06] Anzahl Buffer:              65911
[INFO] [2025-03-04 09:09:06] Anzahl Sätze (gesamt):      842393
[INFO] [2025-03-04 09:09:06] Anzahl Sätze (gespeichert): 80676
[INFO] [2025-03-04 09:09:06] Anzahl Sätze (Dubletten):   7329

gameshacker avatar Mar 04 '25 09:03 gameshacker

@cc13com

Hello @bablokb, I can check in one of my VMs if I will find an old film-list. Let me know if you need help.

That would be great. I don't need the complete filmlist. Just unpack it and post the first 256-1024 chars. It is some sort of json and one very large string but the header is upfront and I would only need the header and maybe one additional line.

That means you don't need an old film list anymore? Sorry, I have no access to my server during the week.

cc13com avatar Mar 06 '25 06:03 cc13com

Hallo, thanks the next branch version works without failure.

[INFO] [2025-03-04 09:09:06] Anzahl Buffer:              65911
[INFO] [2025-03-04 09:09:06] Anzahl Sätze (gesamt):      842393
[INFO] [2025-03-04 09:09:06] Anzahl Sätze (gespeichert): 80676
[INFO] [2025-03-04 09:09:06] Anzahl Sätze (Dubletten):   7329

For me the "next" branch works fine. Thanks!

cc13com avatar Mar 06 '25 06:03 cc13com

Fixed with 4d1335e043f5cf8b24c9502a14c7e498a5635fc2

bablokb avatar Mar 07 '25 07:03 bablokb