Tagged Questions
0
votes
1answer
16 views
Flask pagination example wont work missing “iter_pages”
I am working on a small web app to view some logfiles. But the
queries I issue to the database use to get very big.
I wanted to implement some pagination following this example pagination.
I put the ...
0
votes
0answers
8 views
Custom view in python camelot
I try to create custom view based on this doc: http://python-camelot.readthedocs.org/en/latest/doc/views.html
def setup_views():
from sqlalchemy.sql import select, func, and_
from ...
0
votes
0answers
7 views
SQLAlchemy after_insert triggering celery tasks
I'm initiating celery tasks via after_insert events.
Some of the celery tasks end up updating the db and therefore need the id of the newly inserted row. This is quite error-prone because it appears ...
0
votes
0answers
7 views
SQLAlchemy bulk insert failing
I am doing bulk inserts using SQLAlchemy in a loop as follows:
for table, batch in pendingInserts:
self.conn.execute(table.insert(), batch)
where batch is list of dict and table is a SQLAlchemy ...
-4
votes
0answers
16 views
Rendering sql output on web with sqlalchemy engine on flask
I have an application built on Python-Flask framework. What I am trying to do is display a sql table output on a page of my website and i do this by connecting SQLAlchemy to an external populated ...
0
votes
0answers
16 views
Get last record of a day using joins in Flask-SQLAlchemy
I have a table of data given timestamps and a couple of values where I want to get the last value of each day.
In raw SQL I would do it like this:
SELECT strftime('%Y-%m-%d', a1.created_at) AS ...
-1
votes
2answers
30 views
How to store Chinese in MySQL?
I already set
character-set-server = utf8
In my.cnf.
I restarted the server and recreated the database, but when I tried to insert Chinese into database, I received this error:
ERROR 1366 ...
0
votes
1answer
13 views
How do I express a function that returns a setof record in sqlalchemy?
I need to execute a pg function that returns a setof record type.
Here is the function in postgres:
CREATE OR REPLACE FUNCTION testfunction(text, text)
RETURNS SETOF RECORD AS
'select * from ...
0
votes
0answers
10 views
SQLAlchemy blocking in custom MySQL functions
I'm using SQLAlchemy in combination with some custom created MySQL functions.
Given a stored MySQL function
FUNCTION `get_foo_id`(`p_filename` CHAR(64), `p_filetype` CHAR(2))
My Python/SQLAlchmy ...
1
vote
1answer
14 views
sqlalchmey session.close() not closing connection
How session is able to output user objects even after session.close() is executed ?
__init__.py
def get_db(request):
maker = request.registry.dbmaker
session = maker()
def ...
0
votes
0answers
7 views
Looking for a portable way of connecting to SQL Server via python SQLAlchemy
I am looking for an easy way to connect to SQL Server from python, one that should work from Linux, OS X and Windows.
It seems that there are lots of SQL Server drivers for SQL Alchemy but so far I ...
0
votes
1answer
19 views
How to return multiple models/tables flask-sqlalchemy?
I want to get data from multiple tables so I did this with sqlalchemy:
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()
a = db.aliased(Employee, name='Employee')
b = db.aliased(Person, ...
2
votes
2answers
27 views
Transaction manager revert/rollback last commit
I try to speedup my tests by putting test data from test case setUp() to setUpClass()/teardownClass class method, so it does not recreate same select only fixture for every test in test case.
...
0
votes
1answer
9 views
Creating self-referential keys in SQLAlchemy
I am not able to create a relationship with a self-referential foreign key in SQLAlchemy. My model looks like:
class Category(db.Model):
__tablename__ = 'categories'
category_id = ...
0
votes
1answer
19 views
Modify Flask-SQLAlchemy query result
I want to modify the results from a flask-sqlalchemy query by before sending them to render_template().
The view queries and modifies the items:
items = Items.query
for i in items:
date = ...
0
votes
0answers
9 views
MySQL Alchemy, Creating a new empty class for every table
Is there a more elegant solution than passing unique classes to each table you want to use in MySQL alchemy mapper class.
Here is how I'm doing it based on the documentation:
from sqlalchemy import ...
4
votes
1answer
73 views
Isolation level with Flask-SQLAlchemy
I'm having trouble understanding how database isolation levels work with Flask-SQLAlchemy, and especially how to really commit changes or close a session. Here is the context of my problem :
I'm ...
0
votes
1answer
14 views
SQLAlchemy initialize_db.py - Having trouble with the initial data fill syntax
I have the following tables:
Schema | Name | Type | Owner
--------+----------------+-------+---------
public | fds_funds | table | finance
public | fdt_fund_types | table | ...
0
votes
2answers
33 views
Why add self instead of self.last_seen in sqlalchemy db (Flask)
In this code the last_seen field is being refreshed with the current time whenever the user uses the site. However, in the call to the db, he (Minuel Grindberg "Flask Web Development") adds self ...
0
votes
1answer
29 views
issue with dates and flask-restful
I'm trying to get flask-restful to return a datetime field, however it fais with the error:
MarshallingException: 'datetime.date' object has no attribute 'utctimetuple'
The model(sqlalchemy) is ...
0
votes
0answers
13 views
Python 2.7, use Pandas/SQLAlchemy to save to Postgres with SET ROLE
I would like to use the Pandas (0.14.1) module with SQLAlchemy support to save a Pandas dataframe as a Postgres table.
DF.to_sql(...) works as expected, of course. However, due to the permissions ...
1
vote
0answers
17 views
use table entries instead of subfactory
I have a FactoryBoy factory for my MyUser class, assigning a default name and a corresponding company:
class MyUserFactory(SQLAlchemyModelFactory):
class Meta: ...
0
votes
0answers
15 views
How do I configure sqlalchemy to correctly store emoji?
With sqlalchemy 0.9.7, I am trying to store emoji into MySQL 5.5 with utf8mb4 enabled. However, for some reason sqlalchemy is killing my emoji chars and I cannot figure out why. I can see the emoji ...
0
votes
2answers
28 views
Flask-SQLAlchemy Constructor Confusion
Once again this code is from Miguel Grindberg's book "Flask Web Development". In models.py we have 3 classes, a Role class which has 3 roles (User, Moderator, Administrator), a User class (id, ...
1
vote
1answer
10 views
ArgumentError: relationship expects a class or mapper argument
I am getting this strange error, and I'm saying strange because I made a change to an unrelated table and now I am getting this error.
I am trying to query my tDevice table which looks like this:
...
1
vote
0answers
27 views
+50
Undo `lazyload()` with the relationship default
I have a Query object which was initially configured to lazyload() all relations on a model:
query = session.query(Article).options(lazyload('author'))
Is it possible to revert the relationship ...
2
votes
1answer
27 views
python module import conundrum (module from submodule)
I have the following project structure:
./app/__init__.py
./app/main/__init__.py
./app/main/views.py
./app/models.py
./app/resources/__init__.py
./app/resources/changesAPI.py
./config.py
./manage.py
...
0
votes
1answer
20 views
SQLAlchemy Inheritance prevent of creating base instance
I have created the following model:
class Person(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(1024), nullable=False)
email = ...
0
votes
1answer
15 views
How to provide the sort order in a variable in sqlalchemy?
Right now what I am doing is as :
if order_type == 'desc':
result = session.\
query(Customer).\
order_by(desc(getattr(Customer, sorting_column_name))).\
...
0
votes
1answer
13 views
how to apply LIMIT/OFFSET on large table in sqlalchemy while getting intermediate result as well [please read the details below]?
I want to do 3 operations on a table which contains large number of records: (1)filter (based on a search query) (2)order_by (on a single column in asc/desc) and (3)slice (for given offset and limit ...
0
votes
1answer
20 views
Generate user ids in a sequence using sqlalchemy in sqllite databse. [on hold]
I need to give Guest users ids ie,guest1,guest2... How can I make sqllite generate such ids using sqlalchemy.
0
votes
0answers
12 views
SQLAlchemy Dictionary Based Collection
I have been reading SQLAlchemy Documentation, and find out this attribute_mapped_collection function could be useful for what I need. However, attribute_mapped_collection function requires a Column of ...
1
vote
2answers
23 views
check if .one() is empty sqlAlchemy
I am running a query based off of other ids for the query. The problem i have is that sometimes the query won't find a result. Instead of having the entire program crash, how can I check to see if the ...
-2
votes
1answer
18 views
Indenting db.commit() in sqlalchemy script
I know this should be a elementary question, but for some reason it doesn't make sense to me. I don't understand why the line db.session.commit() isn't indented under the for statement for r in ...
0
votes
1answer
25 views
Filtering on unicode column names
I would like to query a mssql database with the column name u'F\u0151biztos\xedt\xf3' using sqlalchemy (I'm using the pymssql driver). I've mapped this column name to an ascii column key, called ...
1
vote
1answer
24 views
delete one-to-one relationship in flask
I'm currently developing an application using flask and I'm having a big problem to delete items in an one-to-one relationship. I have the following structure in my models:
class User(db.Model):
...
1
vote
0answers
31 views
Splitting up a Flask application?
I have a large-ish Flask project (using Flask-SQLAlchemy) which has a core component which involves processing a large amount of data and then saving the results to a database. It has its own set of ...
0
votes
1answer
22 views
Replace Character For All Rows using SQLAlchemy on Flask
I made the mistake of accidentally using non-ascii characters in a form that was submitted into a database using SQLAlchemy, running on Flask. Basically, rather than using the ASCII hyphen –, I used ...
0
votes
0answers
21 views
Serialize SQLAlchemy Objects that have children with multiple children
I have an SLQALchemy object that I am serializing with marshmallow.
The object has N likes and N comments. It looks like this:
class Parent():
__tablename__ = 'parent'
title = ...
1
vote
1answer
12 views
get table columns from sqlAlchemy table model
I have a table that where I would like to fetch all the column names however after browsing the interwebs I could not find a way that works. This is what my table looks like:
class myTable(Base):
...
0
votes
0answers
19 views
adding first object to db session doesn't return id but second object does
as I am iterating a loop I am creating a table object(SubReport) in python using sqlAlchemy, then inside a nested for loop I create another object(Inspection) (parent object has children hence why I'm ...
1
vote
0answers
11 views
Sql Alchemy QueuePool limit overflow
I have a Sql Alchemy application that is returning TimeOut:
TimeoutError: QueuePool limit of size 5 overflow 10 reached,
connection timed out, timeout 30
I read in a different post that this ...
1
vote
1answer
27 views
How to choose database binds in flask-sqlalchemy
I have two database binds in Flask - 'default' and 'sus'. I used bind_key in Model, it worked OK.
class Person(db.Model):
__tablename__ = 'persons'
__bind_key__ = 'sus'
id = ...
1
vote
1answer
35 views
SQLAlchemy one to many relationship, how to filter the collection
Bacially Product has a one to many relationship to ProductPicture.
My product picture model looks like this:
picture_type_enums = ('main', 'related', 'option')
class ProductPicture(Base):
...
0
votes
2answers
12 views
Mapping non-ascii, long column names in SQLAlchemy fails with NoSuchColumnError
Could it be that RowProxy objects' keys are truncated to some length?
I've a legacy MSSQL database that has some column names with accented letters.
I'm mapping it's columns to python properties ...
0
votes
1answer
8 views
Accented column names, introspection and mapping
I would like to access a legacy MSSQL database using SQLAlchemy. With basic schema inspection I could already list the columns of the tables I'm interested in. Unfortunately, these column names ...
0
votes
0answers
34 views
How to insert record with a many-to-many relationship?
I have a class Consignments in this class I have a relationship to a Sims class:
class Consignments(Base):
__tablename__ = "consignments"
id = Column(
Integer,
...
0
votes
1answer
33 views
One-to-one relationship in Flask
I'm trying to create a one-to-one relationship in Flask using SqlAlchemy. I followed this previous post and I created the classes like ones below:
class Image(db.Model):
__tablename__ = 'image'
...
0
votes
1answer
16 views
How to get sqlite file name in SQLAlchemy engine connect event
I am using following code to set secret for sqlcipher version of sqlite. It has to be the first command sent to database. Therefore I can't use PRAGMA database_list; to get the filename, because I ...
3
votes
1answer
43 views
Strange error after SQLAlchemy update: 'list' object has no attribute '_all_columns'
Here's a simplified version of my query:
subquery = (select(['latitude'])
.select_from(func.unnest(func.array_agg(Room.latitude))
...