learn-co-curriculum / python-p4-building-get-api

Other
0 stars 961 forks source link

db.init_app duplicated in debug file #5

Open samchappel opened 1 year ago

samchappel commented 1 year ago

Canvas Link

https://learning.flatironschool.com/courses/6259/assignments/233439?module_item_id=547397

Concern

There is a part of this lab that asks your to run python debug.py to enter the interactive shell and enter the following code: game = Game.query.first() game.to_dict() => Can not serialize type:Review => Can not serialize type:Review => Can not serialize type:Review => {'title': 'Beat go these.', 'created_at': '2022-09-12 16:45:47', 'id': 1, 'genre': 'Racing', 'platform': 'NES', 'reviews': [], 'price': 29, 'updated_at': None}

There is a duplicate db.init_app in the debug file that is causing this error when you try to run python debug.py: Traceback (most recent call last): File “debug.py”, line 10, in db.init_app(app) File “/Users/stevepassarelli/Development/code/phase-4/python-p4-building-get-api/.venv/lib/python3.8/site-packages/flask_sqlalchemy/extension.py”, line 253, in init_app raise RuntimeError( RuntimeError: A ‘SQLAlchemy’ instance has already been registered on this Flask app. Import and use that instance instead. (python-p4-building-get-api) stevepassarelli@steves-MacBook-Pro server % python debug.py

I know troubleshooting is good practice, but when this material is still so new to us and presented in a way that isn't functional, it makes it hard to know if we're doing something wrong.

Additional Context

No response

Suggested Changes

No response

pgill97 commented 1 year ago

Removed init_app line from main and solution

sheenasany commented 1 year ago

I had actually forked this lab yesterday so didn't see the changes made recently regarding removing the init_app line. However, after going through the issues on this lab, I went ahead and deleted the init_app line on my end to see if that does anything, but I'm still coming across a problem when in the ipdb. Even though, I'm able to run python debug.py and get into ipdb, I'm still getting an error saying that 'Game is not defined.."

Screenshot: image

Here's what the model.py and app.py look like: image

image

Haven't gone through the rest of the lab just yet because I wanted to see what was actually happening in ipdb. I also had a student that came across the same issue so hoping that this can be resolved fairly quickly.

professor-ben commented 1 year ago

Hey Sheena,

This one was weird. For some reason, the code in debug.py- the same as in any other debug.py- fails. I think we need to reformat this one to generate an app_context differently or provide instructions on how to do that in the shell. (I looked into this for a while and genuinely have no idea what the difference is between this and the very next lesson).

Look forward to a change soon. Thanks for reporting.

-Ben

professor-ben commented 1 year ago

Hi Sheena,

In a very confusing development, this is working on my end now that I've cloned the repo with Prabhdip's changes. Can you try reforking the repo to check it on your end?

Sorry for a weird one, Ben