0

I have a test flask application running on glcoud http://to-do-list-309620.appspot.com/

There is json http://to-do-list-309620.appspot.com/api/tasks/ Each time I call it it gives me different result. Even local! http://127.0.0.1:8000/api/tasks/ Thats means for me I have a problem with SQL (app was tested on sqlight local before and it was ok) Any ideas whats going wrong with Google Cloud SQL and how can I prevent it for this project?

My function is using sqlalchemistry:

    def main(id,request):
    import datetime
    Task = Tasks.query.order_by(Tasks.time_create.desc())
    tasks_schema = TasksSchema(many=True)
    resp=tasks_schema.dump(Task)
    return resp

and models are:
class Tasks(db.Model):
    __tablename__ = 'tasks'
    task_id = db.Column(db.Integer, primary_key=True)
    task_name = db.Column(db.String(255),nullable=False)
    time_create = db.Column(db.String)
    status = db.Column(db.Integer, default = 0)
    def __repr__(self):
        return '<Tasks {}>'.format(self.task_name)

class TasksSchema(ma.Schema):
    task_id = fields.Int()
    task_name = fields.Str()
    status = fields.Int()
    time_create = fields.Method("format_date", dump_only=True)
    ordered=True
    def format_date(self, Tasks):
        return Tasks.time_create

UPD: found! MySQL data is caching with google cloud SQL and SQLAlchemy

D M
  • 29
  • 3
  • I reloaded `http://to-do-list-309620.appspot.com/api/tasks/ ` a few times and it's in the same order every time. `222` is first, `mysql...` is 3rd, then `sdsdsd` and last is `333`. – aneroid Apr 07 '21 at 08:36
  • Try to add http://to-do-list-309620.appspot.com/ a new line. You can see then json is random. – D M Apr 07 '21 at 10:53
  • UPD: there is flask cache on sql query! https://stackoverflow.com/questions/55551698/mysql-data-is-caching-with-google-cloud-sql-and-sqlalchemy – D M Apr 08 '21 at 11:53
  • Ey, did the solution from the other post work? If it did so would be great to have an answer and mark it as solved to make it easier for other people to find it. – Anton L Jun 03 '21 at 12:49

0 Answers0