8

I'm doing a Flask course but when I run this code, it throws an error:

for origin, destination, duration in reader:
        db.execute("INSERT INTO flights (origin, destination, duration) VALUES (:origin, :destination, :duration)",
                    {"origin": origin, "destination": destination, "duration": duration})
        print(f"Added flight from {origin} to {destination} lasting {duration} minutes.")
db.commit()

The error in the last line (db.commit(), and db.execute()):

db: scoped_session
Instance of 'scoped_session' has no 'commit' memberpylint(no-member)

What can I do to fix it? I already installed the package sqlalchemy that other questions suggests.

  • Why does it end in "pylint(no-member)"? Are you running the code itself, or are your running it somehow through pylint? – Iguananaut Dec 06 '19 at 13:48
  • The error appear in vscode –  Dec 06 '19 at 13:48
  • I just open the file and throws –  Dec 06 '19 at 13:49
  • I'm 99% sure that that isn't true. You haven't shown how you set up the connection – roganjosh Dec 06 '19 at 13:50
  • https://imgur.com/2WxEusw –  Dec 06 '19 at 13:55
  • Does this answer your question? [Specific class for generated-members in pylint?](https://stackoverflow.com/questions/51168479/specific-class-for-generated-members-in-pylint) – Iguananaut Dec 06 '19 at 14:08
  • Try actually running the code. This is just VSCode giving an "error" in advance based on some static analysis, but it does not necessarily mean there's a real error. I believe this to be a possible false-positive. Did you actually *run* the code or is this just based on on what VSCode is telling you in the editor? – Iguananaut Dec 06 '19 at 14:09

1 Answers1

18

The error is thrown by Pylint which is a static code checker, it can introduce false positives at times, it does not mean that your code does not work.

You need to tell pylint to ignore scoped_session by adding this line to the .pylintrc file:

ignored-classes=scoped_session

If you don't have a .pylintrc file, you can run this:

 pylint --generate-rcfile > pylintrc
Dani G
  • 1,202
  • 9
  • 16
  • 4
    @roganjosh looks like he's running it through pylint, look at the error he's getting(memberpylint): Instance of 'scoped_session' has no 'commit' memberpylint(no-member) – Dani G Dec 06 '19 at 13:58
  • 1
    Yeah, this is correct. They're not even running the code, it's just pylint in VSCode giving a static checker error. – Iguananaut Dec 06 '19 at 14:07
  • @roganjosh your comments here are quite annoying given the fact that you are wrong... I actually ran into the same problem (yes, without running my code!! still got me wondering...), knowing that pylint is just pylint and not the interpreter itself. Alternatively one can do `#pylint:disable=no-member` for the lines in question. However I find Dani's answer more compelling. – Robert Mar 23 '22 at 10:16
  • @Robert deleted – roganjosh Mar 26 '22 at 07:28