flask-sqlalchemy

Pylint can't find SQLAlchemy query member

吃可爱长大的小学妹 提交于 2019-12-02 16:09:33
I have a Flask (v0.10.1) application using Flask-SQLAlchemy (v2.0) and I'm trying to configure Pylint to check it. Running with Python 3.4.2. First error was: Instance of 'SQLAlchemy' has no 'Table' member (no-member) And I fixed this one ignoring the check for member attributes on SQLAlchemy: ignored-classes=SQLAlchemy But I'm having a problem with the query member on entities: Class 'UserToken' has no 'query' member (no-member) Is there any way to fix this issue without having to ignore no-member errors on every query call? Flask bootstrap: from flask import Flask from flask_sqlalchemy

Flask with create_app, SQLAlchemy and Celery

落花浮王杯 提交于 2019-12-02 15:17:39
I'm really struggling to the get the proper setup for Flask, SQLAlchemy and Celery. I have searched extensively and tried different approaches, nothing really seems to work. Either I missed the application context or can't run the workers or there are some other problems. The structure is very general so that I can build a bigger application. I'm using: Flask 0.10.1, SQLAlchemy 1.0, Celery 3.1.13, my current setup is the following: app/__init__.py #Empty app/config.py import os basedir = os.path.abspath(os.path.dirname(__file__)) class Config: @staticmethod def init_app(app): pass class

What is the best way to update all clients when Flask database changes without polling?

梦想的初衷 提交于 2019-12-02 11:42:15
Currently I have a Flask server that runs a small web frontend as well as a command line interface to that same server. The basic idea looks like this: <Top section: allows file upload> * list of files from database <Second section: allows file manipulation/ upload> * list of files from database <Third section: Not files, but still allows for database changes> * list of things made from database Now this works well from the front end, but currently if the CLI or another client makes a change to the database, it doesn't update other clients. I have it somewhat working with JS polling and

Sqlalchemy convert epoch time to date in group by

╄→尐↘猪︶ㄣ 提交于 2019-12-02 10:42:38
I am using Sqlalchemy as ORM for PSQL db. My timestamps are stores as epoch times in my database eg, 1525868337991. (in milli sec) I am writing a query to get count of employees on a particular date(grouping by on date). I am not able to find any way by which, I can convert epoch to date in my ORM query, like psql has to_timestamp . The query is written below : employees_details = db.session.query( func.count(EmployeeInfo.id).label("employee_count"), EmployeeInfo.employee_created_on, EmployeeSourceInfo.employee_source_display_name ).join( EmployeeSourceInfo, EmployeeInfo.lead_source_id ==

update state with flask sqlalchemy with postgres will not commit to database

徘徊边缘 提交于 2019-12-02 09:23:44
I have read quite a bit of documentation and I can't see what is wrong with these lines update_this = User.query.filter_by(email=email).first() update_this.emailconfirmed = True db.session.commit() ...and yet when I deploy the boolean column 'emailconfirmed' never is update to True. I have confirmed with print statements that update_this.emailconfirmed is False at the exact point in the code shown above... I just can't seem to update that value. Does anybody know what tests I can do, what imports I should check etc. etc. Right now this is the top of my main .py file where the above code

TypeError: __init__() got an unexpected keyword argument 'password'

安稳与你 提交于 2019-12-02 08:46:27
问题 I can't find out what's the cause of this error TypeError: __init__() takes at most 2 arguments (3 given) which is pointing to @user_blueprint.route('/login', methods=['GET', 'POST']) def login(): if g.user.is_authenticated: flash("You are already Logged in", 'warning') return redirect(url_for('members')) error = "" form = LoginForm() if request.method == 'POST': if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is not None and bcrypt.check

How to query many-to-many based on some constraints in flask sqlalchemy?

£可爱£侵袭症+ 提交于 2019-12-02 08:31:57
If I have a User and Item model, and they have a many-to-many association with each other, how do I build a query that returns: (1) All items that belong to any user named 'Bob' I tried: Item.query.filter(User.name == 'Bob') Which returns all items regardless of the user's name (incorrect) (2) All items that have the name 'shark' and belong to any user named 'Bob' I tried: Item.query.filter(User.name == 'Bob' & Item.name == 'shark') Same as above, but only returns items named 'shark' regardless of the user's name. (incorrect) My model definitions: association_table = Table('items_users',

How to filter exact many to many

二次信任 提交于 2019-12-02 08:20:09
I have User and Room model in Flask SQLAlchemy. I need to filter if Room exists with users [user1, user2, ...]. Filter must be exact. Here are my models: room_users_table = db.Table( 'room_users', db.metadata, db.Column('user', db.Integer, db.ForeignKey('user.id')), db.Column('room', db.Integer, db.ForeignKey('room.id')) ) class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(80)) last_name = db.Column(db.String(80)) password = db.Column(db.String(80)) email = db.Column(db.String(120), unique=True) rooms = db.relationship(

SQLAlchemy @property causes 'Unknown Field' error in Marshmallow with dump_only

江枫思渺然 提交于 2019-12-02 07:24:36
I'm using flask-marshmallow (marshmallow=v3.0.0rc1, flask-marshmallow=0.9.0) and flask-sqlalchemy (sqlalchemy=1.2.16, flask-sqlalchemy=2.3.2) I have this model and schema. from marshmallow import post_load, fields from .datastore import sqla_database as db from .extensions import marshmallow as ma class Study(db.Model): _id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) tests = db.relationship("Test", backref="study", lazy='select', cascade="all, delete-orphan") @property def test_count(self): return len(self.tests) class StudySchema(ma.ModelSchema): test

AttributeError: 'NoneType' object has no attribute 'time_recorded' in Flask, SQLAlchemy

寵の児 提交于 2019-12-02 07:08:42
I have an api endpoint that passes a variable which is used to make a call in the database. For some reason it cannot run the query yet the syntax is correct. My code is below. @app.route('/api/update/<lastqnid>') def check_new_entries(lastqnid): result = Trades.query.filter_by(id=lastqnid).first() new_entries = Trades.query.filter(Trades.time_recorded > result.time_recorded).all() The id field is: id = db.Column(db.String,default=lambda: str(uuid4().hex), primary_key=True) I have tried filter instead of filter_by and it does not work. When I remove the filter_by(id=lastqnid) it works. What