PacktPublishing / Building-Data-Science-Applications-with-FastAPI

Building Data Science Applications with FastAPI, Published by Packt
MIT License
306 stars 157 forks source link

excute(update_query) return influenced rows #5

Closed 66dexmg closed 2 years ago

66dexmg commented 2 years ago

https://github.com/PacktPublishing/Building-Data-Science-Applications-with-FastAPI/blob/da186755fba69a56917a222caa19661a8c19fc8b/chapter6/sqlalchemy/app.py#L91 I have tried in my code.Maybe the method 'execute' for 'update' return influenced rows not the primary-key id.And I know that in the 'insert' condition new id was returned. So maybe 'post.id' should be the parameter instead of 'post_id' in next function.

frankie567 commented 2 years ago

Hi @66dexmg πŸ‘‹

Do you get a specific error when doing this?

66dexmg commented 2 years ago

@frankie567 Yes,it may be a small mistake.In next row,i can only get first post which was not the post i updated because the function 'execute' always return the number 1.

frankie567 commented 2 years ago

You're perfectly right @66dexmg, that's actually quite a dumb mistake from my part. You can find the correct, fixed code here: https://github.com/PacktPublishing/Building-Data-Science-Applications-with-FastAPI/commit/e95e35f484809e937071e45a3c1f6fcab83fd8f7

I'll now contact Packt to coordinate a proper erratum. Thank you for raising this πŸ™

66dexmg commented 2 years ago

@frankie567 You are welcome.You have written a fantastic book although I had waitted its Chinese translation for a long timeπŸ˜€.Any oriented advice for me after I finish it?

frankie567 commented 2 years ago

Thanks!

Well, my main advice to fellow developers is usually: practice. It's by experimenting a lot, building new things, observe what others are doing in their code that you'll make progress and gain experience.

That said, there are a few subjects I didn't have the opportunity to show in the book that are interesting:

66dexmg commented 2 years ago

Thanks a lot!