mfreeborn / fastapi-sqlalchemy

Adds simple SQLAlchemy support to FastAPI
MIT License
619 stars 38 forks source link

Add session variable to DBSession init #17

Closed teamhide closed 4 years ago

teamhide commented 4 years ago

While using db.session on pycharm, it notify Unresolved attribute reference 'session' for class 'DBSession' errors.

To avoid it, added self.session to DBSession.

codecov-commenter commented 4 years ago

Codecov Report

Merging #17 into master will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #17   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines           60        61    +1     
=========================================
+ Hits            60        61    +1     
Impacted Files Coverage Δ
fastapi_sqlalchemy/middleware.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b46b9e6...4df5289. Read the comment docs.

mfreeborn commented 4 years ago

Thanks for the PR. I don't use Pycharm myself. Happy to resolve this problem. Could I ask you to try one alternative and tell me if this fixes it? Instead of adding self.session = None, what happens if you change line 82 of middleware.py from db: DBSession = DBSession to db: DBSessionMeta = DBSession? Does that fix it or not?

teamhide commented 4 years ago

Works perfectly. I will re-pr for this issue.