mpope9 / nba-sql

:basketball: An application to build an NBA database backed by MySQL, Postgres, or SQLite
Apache License 2.0
172 stars 20 forks source link

Peewee error? #58

Closed rogersheu closed 2 years ago

rogersheu commented 2 years ago

Hello, I'm getting the following issue when trying to download via SQLite on Windows. I'm still able to run SQLite, do SQL queries, and all that, so it must not be affecting functionality too much. I assume maybe I'd created the team.team_id database entries previously and it was just clashing because it had to overwrite it? I'm relatively new to all this so it could be some dependency I don't have or something to do with my system.

Traceback (most recent call last):
  File "peewee.py", line 3144, in execute_sql
sqlite3.IntegrityError: UNIQUE constraint failed: team.team_id

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "nba_sql.py", line 394, in <module>
  File "gooey\python_bindings\gooey_decorator.py", line 134, in <lambda>
  File "nba_sql.py", line 218, in main
  File "nba_sql.py", line 343, in populate_base_tables
  File "general_requester.py", line 51, in populate
  File "db_utils.py", line 15, in insert_many
  File "db_utils.py", line 28, in __insert_many_sqlite
  File "peewee.py", line 1907, in inner
  File "peewee.py", line 1978, in execute
  File "peewee.py", line 2745, in _execute
  File "peewee.py", line 2474, in _execute
  File "peewee.py", line 3157, in execute
  File "peewee.py", line 3151, in execute_sql
  File "peewee.py", line 2917, in __exit__
  File "peewee.py", line 190, in reraise
  File "peewee.py", line 3144, in execute_sql
peewee.IntegrityError: UNIQUE constraint failed: team.team_id

Thanks in advance!

mpope9 commented 2 years ago

Hi! It sounds like you created the database already and are trying to re-run the app on the existing database. Is that correct?

The app isn't very sophisticated when it comes to updating a database. Maybe this is a good place to start.

It looks like we're using db_utils.insert_many for the team table. Maybe it'd make more sense to call db_utils.insert_many_ignore_on_conflict.

I can try to make this change tonight or tomorrow, unless you would like to take a crack at it?

Also, are you using the windows client in the release or did you build your own?

rogersheu commented 2 years ago

Hi! It sounds like you created the database already and are trying to re-run the app on the existing database. Is that correct?

Most likely. The first time I ran it, I think I ran into a completely different error, but I remember resolving it (and I do not recall what caused it). So any/every subsequent attempt likely threw this error.

It looks like we're using db_utils.insert_many for the team table. Maybe it'd make more sense to call db_utils.insert_many_ignore_on_conflict.

Does it make sense to do this on_conflict_ignore call everywhere where relevant? Or maybe it should throw some warning/clarification (or error/exception) message?

Also, are you using the windows client in the release or did you build your own?

I used your 0.0.4 alpha release Windows client.

Also, nice seeing you outside the confines of the NBA (and UtahJazz) subreddit! Cool application you've provided here.

mpope9 commented 2 years ago

OK, I am sitting on a PR that I forgot to merge. It should make this easier going forward. It includes a --skip-tables option that takes the team table as an option. I'll see if I can clean that up and merge it tonight and cut a new windows release. I will tag you in a comment here when its done and we can see if it solves the issue.

I'd like to limit on_conflict_ignore to base tables like team, as I feel like it could cause data issues but I'm not 100% certain. I think merging the expanded --skip-tables option is better overall.

And thank you!

mpope9 commented 2 years ago

PR here for reference: https://github.com/mpope9/nba-sql/pull/59

rogersheu commented 2 years ago

Sounds good!

rogersheu commented 2 years ago

Small side question @mpope9 . Can data from 2021-22 be pulled for this database? In the .exe dialog box, it went up to 2020-21, but if I wanted to do a 2020-21 vs. 2021-22 comparison, could I go about doing that?

Thanks!

mpope9 commented 2 years ago

Since I'm making the PR I'll just toss that in because it is a one line change.

mpope9 commented 2 years ago

@rogersheu Wanna give this release a try: https://github.com/mpope9/nba-sql/releases/tag/v0.0.5 You can select multiple tables to skip the regular way by holding shift. I don't use the GUI much so let me know if there are any issues.

rogersheu commented 2 years ago

Tried running it on both 2021-22 and 2020-21 (separately) and got the same error.

Traceback (most recent call last):
  File "nba_sql.py", line 378, in <module>
  File "gooey\python_bindings\gooey_decorator.py", line 134, in <lambda>
  File "nba_sql.py", line 89, in main
AttributeError: 'Namespace' object has no attribute 'batch_size'

Also would like to mention that in the description for seasons selection, you have the following example usage

--seasons 2019-2020 2020-2021

but it should (probably) be --seasons 2019-20 2020-21

mpope9 commented 2 years ago

ah, I only tested with the commadline version. I'll see what the issue that I caused is. In the meantime, the previous release has --skip-base-tables which should do the trick as well.

rogersheu commented 2 years ago

I ran into the same issue running it from command line. The old version worked both ways.

Maybe it's something on my system's end?

mpope9 commented 2 years ago

I was able to repro it with the GUI version. I'll see what I can do.

mpope9 commented 2 years ago

Ok this should be fixed on master I believe. I can cut another windows build tomorrow, but you can also create your own using this script: https://github.com/mpope9/nba-sql/blob/master/scripts/build_exe.txt

However when doing some testing I noticed that shot_chart_detail is not populated correctly on sqlite, it only works on postgres and mysql. I've filed this follow up for it: https://github.com/mpope9/nba-sql/issues/61

I'll close this issue once I take it out for a spin tomorrow night.

mpope9 commented 2 years ago

Sorry for the delay on this. I re-built the windows client and give it a run through locally. Looks good.

That shot_chart_detail issue was also not real. I just didn't refresh my dbeaver connection when I rebuilt the database. It looks good, too.

You can find the release here: https://github.com/mpope9/nba-sql/releases/tag/v0.0.6 thanks for reporting this!

rogersheu commented 2 years ago

Cool! Thanks for maintaining!

mpope9 commented 2 years ago

Thank you for using đŸ˜„