FAI-CIVL / FAI-Airscore

AirScore - online paragliding / hanggliding GAP-based scoring software.
https://airscore.cc/
GNU General Public License v3.0
13 stars 17 forks source link

comp code generation does not respect field length #192

Open kuaka opened 3 years ago

kuaka commented 3 years ago

When importing from FSDB, the comp code is being generated however it appears that there is no forcing it to not exceed the filed length in the DB.

 | [FLASK]     raise errorclass(errno, errval)
flask_dev_local    | [FLASK] sqlalchemy.exc.DataError: (pymysql.err.DataError) (1406, "Data too long for column 'comp_code' at row 1")

'comp_code': 'FORFLA17_10',

I believe that as I have imported this comp many times before it is adding an index on the end, which now is '10' and the generated code is too long for the DB.

kuaka commented 3 years ago

update: blowing away the DB and reimporting gives the same error with the same code ('FORFLA17_10'). This import was working fine a day (or 2) ago.

biuti commented 3 years ago

I think The code is limited to 10 chars, so 10th repetition of same name is failing. I think it it quite unusual to have so many comps named the same in real life, and as that is a code I wouldn't make it bigger than 10 chars, but I will think a solution to fail without breaking. Meanwhile delete folders in tracks.

kuaka commented 3 years ago

yes it looks like it is becasue I have old track folders. Yes it is something that would be rare, but the point is we are creating a code and trying to send to the DB that exceeds the field length. This is 'not great' code and something that a unit test should pick up...

biuti commented 3 years ago

Related to this, I changed delete comp function to delete comp folder (if files are selected to be deleted but at the moment it is the only option)( https://github.com/FAI-CIVL/FAI-Airscore/commit/ba519633ad8db5592e38378078730dcd561ebe41) I also changed the function to create comp code, now it cannot go over 10 chars (https://github.com/FAI-CIVL/FAI-Airscore/commit/774fb7f0c7d1c1fb092e2592be4e0284e304a0e3).

kuaka commented 3 years ago

Great. The other files will also need to be deleted. I am not sure if they are or not.

biuti commented 3 years ago

Yes it deletes everything, included results and map files.

kuaka commented 3 years ago

I also changed the function to create comp code, now it cannot go over 10 chars (774fb7f).

my advice would be to write a unit test for this. Should never create the same code for the same comp (if already exists) and never go over 10 chars.

biuti commented 3 years ago

Yes now it goes through all the alphabet, so we have 64 slots for events with same name and season. I think it should be enough, but I can add an error message just in case routine is not able to create a unique short name.

biuti commented 3 years ago

I tested a bit and should work correctly now.