HugoFara / lwt

Learn languages by reading! A language learning app stemmed from Learning with Texts (LWT).
https://hugofara.github.io/lwt/
The Unlicense
169 stars 19 forks source link

Rare error when updating a word with tags #120

Open HenryWales opened 1 year ago

HenryWales commented 1 year ago

I have edited many words with tags before first seeing this error. I don't know what can be making it happen sometimes and sometimes not. Most of the time it appears to work as expected.


Fatal Error in SQL Query: INSERT INTO tags (TgText) VALUES('some_tag')

Error Code & Message: [1062] Duplicate entry 'some_tag' for key 'TgText'

Backtrace:

#0 C:\xampp\htdocs\lwt\inc\database_connect.php(57): do_mysqli_query('INSERT INTO tag...')
#1 C:\xampp\htdocs\lwt\inc\session_utility.php(278): runsql('INSERT INTO tag...', '')
#2 C:\xampp\htdocs\lwt\edit_words.php(666): saveWordTags(7034)

This leads to some_tag being removed as a tag for the word.

HugoFara commented 1 year ago

That's an annoying bug, I cannot reproduce it :thinking:

I'm not sure of the cause, maybe your server takes too much time to store session data, so it's not detected, but that is only a theory. Maybe we can go for a small experiment. Can you replace line 273 of inc/session_utility.php:

https://github.com/HugoFara/lwt/blob/4d0bbac6747995724bdc485aed3c8645684a7f78/inc/session_utility.php#L273

by this

getWordTags(1);
get_tags(1);

It will force the server to refresh all tags, it increases it's load a bit, but at least we can guaranty the we try to have the good data.

HenryWales commented 1 year ago

The bug hasn't reproduced yet after including the change, but the bug was rare before so it's hard to tell what was happening.

HugoFara commented 1 year ago

Okay, I think I will keep this issue open and investigate a bit further when I will find some time.

See you!