sqlalchemy

Python call sql-server stored procedure with table valued parameter

。_饼干妹妹 提交于 2021-02-04 05:01:25
问题 I have a python script that loads , transform and calculates data. In sql-server there's a stored procedure that requires a table valued parameter, 2 required parameters and 2 optional parameters. In sql server I can call this SP: USE [InstName] GO DECLARE @return_value int DECLARE @MergeOnColumn core.MatchColumnTable INSERT INTO @MergeOnColumn SELECT 'foo.ExternalInput','bar.ExternalInput' EXEC @return_value = [core].[_TableData] @Target = N'[dbname].[tablename1]', @Source = N'[dbname].

Airflow can't pickle _thread._local objects

爱⌒轻易说出口 提交于 2021-01-29 18:48:25
问题 I am currently creating an engine in my DAG and passing this sqlalchemy engine as a parameter to PythonOperator to execute some database work. e.g. PythonOperator(python_callable=my_callable, op_args=[engine], provide_context=True, task_id = 'my_task', dag=dag) When I try to clear the status of tasks, I get an error File "/opt/conda/lib/python3.7/copy.py", line 169, in deepcopy rv = reductor(4) TypeError: can't pickle _thread._local objects This is most likely because you can't pickle engine

How do I get sqlalchemy.create_engine with mysqlconnector to connect using mysql_native_password?

萝らか妹 提交于 2021-01-29 17:28:41
问题 I'm working with pandas and sqlalchemy, and would like to load a DataFrame into a MySQL database. I'm currently using this code snippet: db_connection = sqlalchemy.create_engine('mysql+mysqlconnector://user:pwd@hostname/db_name') some_data_ref.to_sql(con=db_connection, name='db_table_name', if_exists='replace') sqlalchemy , pandas have been imported prior to this. My MySQL backend is 8.x, which I know uses caching_sha2_password . If I were to connect to the database using mysql.connector

How to keep a session open across separate requests with Flask-SQLAlchemy

瘦欲@ 提交于 2021-01-29 15:44:10
问题 I have a webapp that communicates with a postgres database via Flask-SQLAlchemy. The app successfully adds/updates individual images to the database. The calls to func1_add_image , func2_add_image are done via separate fetch request from javascript code. # in python db = sqlalchemy(session_options={'autocommit': False}) ... @bp.route('/api/v1_2/func1_add_image', methods=['POST']) def func1_add_image(): db.session.add(image1) db.session.commit() ... @bp.route('/api/v1_2/func2_add_image',

Is there any order for add versus delete when committing in sqlalchemy

你离开我真会死。 提交于 2021-01-29 14:41:58
问题 I'm adding a bunch of entries to a table in sqlalchemy. If an entry already exists, based on some key, I delete the row in the table and then add the "updated" entry. After finishing deleting and adding all entries I commit the session. However during testing the commit fails due to a unique constraint failure. My understanding from this error is that I'm trying to add the updated entry before deleting the old entry. If I delete the old entry, then commit, then add, everything works ok. So my

SQLAlchemy set default value of column depending on ID

风流意气都作罢 提交于 2021-01-29 11:33:44
问题 I already know that for general cases: this question is sufficient: SQLAlchemy set default value of one column to that of another column But when my column depends on the Id column it doesn't work because id is auto generated. For eg: Using the same example as the other question class Substance(Base): __tablename__ = "substances" id = Column(Integer, primary_key=True) code = Column(String, unique=True) name = Column(String, unique=True) subtance_hash = Column(String, unique=True, default

`flask db migrate` error

ぃ、小莉子 提交于 2021-01-29 10:47:26
问题 We are trying to run a flask db migrate and flask db upgrade which throws the following error: Usage: flask db upgrade [OPTIONS] [REVISION] Error: The file/path provided (C) does not appear to exist. Please verify the path is correct. If app is not on PYTHONPATH, ensure the extension is .py We have added the app's directory to the PYTHONPATH environment variable but still get the error. Any help would be appreciated. Below is our __init__.py code. Are we missing something? import logging from

MySQL query errors when connecting from Celery task running on Heroku

梦想与她 提交于 2021-01-29 10:31:20
问题 I'm seeing wrong query results when executing queries against an external MySQL database, but only when connecting from Celery tasks running on Heroku. The same tasks, when run on my own machine do not show these errors, and the errors only appear about half of the time (although when they fail, all tasks are wrong). The tasks are managed by Celery via Redis, and the MySQL database does not itself run on Heroku. Both my local machine and Heroku connect to the same MySQL database. I connect to

SQL Query to group records and return them as a list in a many-to-one relationship

不想你离开。 提交于 2021-01-29 08:46:00
问题 I'm having a bit of trouble with using SQLAlchemy to its full potential in a Python application using Flask, and understanding how many-to-one relationships work and how they can be utilized. I'm working with a database of songs and artists with a schema that looks like this: CREATE TABLE song ( id INTEGER PRIMARY KEY AUTO_INCREMENT, title VARCHAR(64), artist_id INTEGER ); CREATE TABLE artist ( id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(64) ); Or, through Python SQLAlchemy, it looks

How to sum *count* subqueries with SQLAlchemy?

ぐ巨炮叔叔 提交于 2021-01-29 08:36:38
问题 I have the following models in my DB (Flask-SQLALchemy, declarative approach, simplified): class Player(db.Model): id = db.Column(db.Integer, primary_key = True) ... class Game(db.Model): id = db.Column(db.Integer, primary_key = True) creator_id = db.Column(db.Integer, db.ForeignKey('player.id')) creator = db.relationship(Player, foreign_keys='Game.creator_id') opponent_id = db.Column(db.Integer, db.ForeignKey('player.id')) opponent = db.relationship(Player, foreign_keys='Game.opponent_id')