2

I am developing a web application and trying to migrate from Spyder to VS Code. It was working with the default interpreter, so I created a new venv but when I start the server it does not work with the same code that was working without the venv. Error description:

File "C:\Users\User\Desktop\Flask\app.py", line 77, in index
measurement_mx = rs.all()
AttributeError: 'ResultProxy' object has no attribute 'all' 

I installed exactly the same dependencies with pip install -r requirements.txt.

Can you help me what the solution could be, I could not find this problem unfortunately.

Relevant code snippet:

@app.route('/', methods=['POST', 'GET'])
def index():  
    with engine.connect() as con:
        rs = con.execute(SQL_string)
        measurement_mx = rs.all() #this is the error line
        measurement_list = []
        for row in measurement_mx:
            measurement_list.append(row._data)
        measurement_list = transpose(measurement_list)
    return render_template('index.html', measurement_list=measurement_list )

Thank you in advance!

Joël
  • 2,723
  • 18
  • 36
Shuja
  • 23
  • 3

1 Answers1

3

Welcome to StackOverflow!

The issue could be that your requirements.txt file may specify what packages to install, but not their exact version, so could you please:

  • paste the content of your requirements file?
  • check the packages versions between your two virtual environments?

Some thoughts:

Now, concerning your exact issue: ResultProxy is not an object from flask but from SQLAlchemy, which SQLAchemy v1.4 replaced:

class sqlalchemy.engine.Result(cursor_metadata)

Represent a set of database results.

New in version 1.4: The Result object provides a completely updated usage model and calling facade for SQLAlchemy Core and SQLAlchemy ORM. In Core, it forms the basis of the CursorResult object which replaces the previous ResultProxy interface. When using the ORM, a higher level object called ChunkedIteratorResult is normally used.

(emphasis mine)

Which means you can:

  • either fix SQLAlchemy version in your requirements.txt file,
  • or update your code to cope with current SQLAlchemy syntax.
Joël
  • 2,723
  • 18
  • 36
  • Thank you Joël! I updated SQLAlchemy to 1.4.20 , then ran into this error message: "AttributeError: 'sqlalchemy.cimmutabledict.immutabledict' object has no attribute 'setdefault' " After a bit of Googling, I found that I might need to upgrade Flask-SQLAlchemy as well and that did the job after updating to 2.5.1. Sorry, I cannot upvote you yet because of my missing reputation but your advice was really helpful! – Shuja Feb 11 '22 at 10:46
  • You're welcome! Management of version over time is not easy, but is necessary to avoid such surprises :) – Joël Feb 13 '22 at 20:31