Re: [sqlalchemy] How correct sort items by @hibrid_property

2023-10-30 Thread Simon King
The error you're getting doesn't have anything to do with using the property in an order_by. It's being triggered just by accessing "Product.Rating". WIth hybrid properties, when you access them via the class as you've done here, the "self" parameter is set to the Product class itself. So on the

Re: [sqlalchemy] Difference b/w creating a DeclarativeBase class vs assigning DeclarativeBase()

2023-10-10 Thread Simon King
I don't think this code was ever correct: Base = DeclarativeBase() Before SQLAlchemy 2.0, there was a declarative_base() function that was used in the same way: from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() ...but in SQLAlchemy 2.0, the

Re: [sqlalchemy] Issuing Raw SQL and Returning a List of Objects

2023-08-23 Thread Simon King
My perspective: the SQLAlchemy ORM really comes into its own when you are making use of its Unit of Work system to load a batch of objects from the database, manipulate those objects, and then flush your changes back to the database. If you are only *loading* data then you don't need a lot of the

Re: [sqlalchemy] Change a select clause + add a join automatically

2023-04-20 Thread Simon King
I think this is the intended use for the do_orm_execute event and the with_loader_criteria query option: https://docs.sqlalchemy.org/en/14/orm/session_events.html#do-orm-execute-global-criteria https://docs.sqlalchemy.org/en/14/orm/query.html#sqlalchemy.orm.with_loader_criteria You ought to be

Re: [sqlalchemy] Queries Across 13 Models - How to improve efficiency?

2023-01-27 Thread Simon King
It looks like all your models share the same "id" value - is that right? If so, you ought to be able to load all of them in a single query, something like this (untested): def getmodels(dbsession, id): models = [M1, M2, M3] conditions = [(M.id == id) for M in models] instances =

Re: [sqlalchemy] Breaking Integration with Locust Tests? Having a hard time debugging

2022-11-07 Thread Simon King
The stack trace shows that the exception is being raised in sqlalchemy_utils/types/uuid.py. Looking at sqlalchemy_utils on Github, this is a bug that has been reported and fixed, but the fix hasn't been released yet: https://github.com/kvesteri/sqlalchemy-utils/pull/643 You could either install

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-27 Thread Simon King
< my.alaoui...@gmail.com> wrote: > yes, all tags have a color... > Can you suggest me another way to do this, please? > thank you . > > Le mardi 25 octobre 2022 à 10:52:17 UTC+1, Simon King a écrit : > >> Turn on debug logs (add echo="debug" to your db

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-25 Thread Simon King
LOG > > EXADATA > > DMZ_PRIVE > > > > I hope it's clear, > thank you . > > Le vendredi 21 octobre 2022 à 09:23:48 UTC+1, Simon King a écrit : > >> I don't understand the question. Are you saying that only one tag is >> displayed? If so, that's not a

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-21 Thread Simon King
I don't understand the question. Are you saying that only one tag is displayed? If so, that's not a problem with SQLAlchemy, it's a problem with your template logic. If that's not what you mean, you need to give us more information. What is the value of "server.tags", and what is the output from

Re: [sqlalchemy] Can’t make the Composite Comparator work…

2022-09-16 Thread Simon King
(I haven't used any of these features, so the following is just a guess) In your assertion, you are comparing two *Point instances*. The SQLAlchemy comparator_factory mechanism has not made any changes to the Point class itself, and Point doesn't define __gt__, hence your TypeError. The point of

Re: [sqlalchemy] Just starting with sqlacodegen: wrong command?

2022-06-15 Thread Simon King
degen --version > 2.3.0 > > On Tue, Jun 14, 2022 at 5:25 PM Javier Garcia > wrote: > >> Thanks Simon, do you know how could I install that version as when I >> upgrade the sqlacodegen I still get the version 2.3.0? >> >> Javier >> >> El martes, 1

Re: [sqlalchemy] Just starting with sqlacodegen: wrong command?

2022-06-14 Thread Simon King
Based on the CHANGES file, it looks like --generator is a new option in v3.0.0: https://github.com/agronholm/sqlacodegen/blob/master/CHANGES.rst Simon On Tue, Jun 14, 2022 at 5:06 PM Javier Garcia wrote: > Hi, > > I have tried to run something like this: > > sqlacodegen --generator tables

Re: [sqlalchemy] simple query takes to long

2022-06-09 Thread Simon King
How many rows are you fetching, and how many columns in each row? On Thu, Jun 9, 2022 at 8:37 AM Trainer Go wrote: > Hello Jonathan, > > i already executed the query without using pandas in my programm > > query = "SELECT" > for row in conn.execute(query).fetchall(): > pass > > the result

Re: [sqlalchemy] how i can avoid the existing database table while generating the initial revision using alembic

2022-06-08 Thread Simon King
g autogenerate feature. i > tried with include_object and include_name hooks. but it won't work for me. > after adding hook also alembic touches to existing tables.. > > if you send the code snipet for env.py file.. that will really help me.. > > Thank you. > > On Wed, 8 Ju

Re: [sqlalchemy] how i can avoid the existing database table while generating the initial revision using alembic

2022-06-08 Thread Simon King
If I understand correctly, you used Alembic's "autogenerate" feature to create your migration script. This feature compares the table definitions in your application with the table definitions in the database and then generates a script to alter the database to match your application. You can

Re: [sqlalchemy] Does alembic support multiple databases?

2022-05-13 Thread Simon King
There are a few possibilities. You could have separate configuration files for each database (eg. alembic-dev.ini and alembic-prod.ini), and choose between them with the "--config" command line option. If you want to stick to a single configuration file, you could put both connection strings in

Re: [sqlalchemy] Session management for general functions within a class

2022-04-29 Thread Simon King
It's difficult to debug this without a script that we can run to reproduce the problem. What kind of object is self.db_session? You use it as a context manager without calling it, so I don't think it can be a sessionmaker or a session. You're nesting calls to the context manager: # in

Re: [sqlalchemy] query many-many with asssociation table

2022-04-06 Thread Simon King
I think it should work if you join to the *relationship* explicitly ie. session.query(User).join(User.user_groups).filter(...) Hope that helps, Simon On Tue, Apr 5, 2022 at 9:48 PM Jason Hoppes wrote: > I want to select all users in a particular group. I have a users table, > user_groups

Re: [sqlalchemy] do_connect listener called couple of times

2022-03-23 Thread Simon King
please suggest if I miss anything here? > > Regards, > Pydi > > On Tuesday, March 22, 2022 at 9:33:57 AM UTC-7 Srinu Chp wrote: > >> Hello Simon, >> >> Thank you very much for detail information. >> >> Regards, >> Pydi >> >&g

Re: [sqlalchemy] do_connect listener called couple of times

2022-03-22 Thread Simon King
> Can you please suggestion? > Regards, > Pydi > On Monday, March 21, 2022 at 10:55:09 AM UTC-7 Srinu Chp wrote: >> >> Hello Simon, >> >> Perfect, working as expected in standalone POC. Thank you quick help >> >> Regards, >> Pydi >> >

Re: [sqlalchemy] do_connect listener called couple of times

2022-03-21 Thread Simon King
; > Regards, > Pydi > On Monday, March 21, 2022 at 2:22:04 AM UTC-7 Simon King wrote: >> >> I don't really understand what's going on in your code, but you seem >> to be calling engine.connect() inside your "do_connect" event handler. >> I would expect that

Re: [sqlalchemy] do_connect listener called couple of times

2022-03-21 Thread Simon King
I don't really understand what's going on in your code, but you seem to be calling engine.connect() inside your "do_connect" event handler. I would expect that to trigger another "do_connect" event, which in turn will call engine.connect() again, which will trigger another "do_connect" event, and

Re: [sqlalchemy] None! Can't pickle : it's not the same object as sqlalchemy.orm.session.Session

2022-03-16 Thread Simon King
I haven't used the multiprocessing library, but if it uses pickle to transfer SQLAlchemy objects, it's going to be difficult to make it work. Objects loaded via the SQLAlchemy ORM hold a references to the Session that was used to load them, which in turn holds a reference to a database connection.

Re: [sqlalchemy] Issue "translating" raw SQL to SQLAlchemy ORM query

2022-02-25 Thread Simon King
By default, relationship loading is deliberately not affected by your join conditions. If you want a relationship property to be restricted to the rows you've selected in your query, you need to use the "contains_eager()" query option:

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-25 Thread Simon King
._handle_result(self._connection.cmd_query(stmt)) > File > "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/connection.py", > line 854, in cmd_query > result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) >

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-24 Thread Simon King
you for your help. I am brand new working with SQLalchemy, really > appreciate if you explain how to generate the metadata with the list of > column names from the .CSV to create the tables? > > On Wed, Feb 23, 2022, 3:52 PM Simon King wrote: >> >> Build a list of Column

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-23 Thread Simon King
Build a list of Column objects from the columns in the CSV file, and use that list to create a Table: https://docs.sqlalchemy.org/en/14/core/metadata.html Once you've created the Table, you can insert data into it using the table.insert() method:

Re: [sqlalchemy] Remove/Filter a query.all() results, add a 'virtual' column

2022-02-21 Thread Simon King
Hi, welcome to Python and SQLAlchemy :-) If you want to do some extra filtering on the results, you can iterate over the results, decide whether each item matches your filter conditions, and if it does, append it to a new list, something like this: filtered_results = [] for part in query.all():

Re: [sqlalchemy] SQL expression object expected, got object of type instead

2022-01-27 Thread Simon King
> > Given the above example, if query(Genome.id) or query(Genome.created_date), > it works fine. But if I query the property, query(Genome.attributes): it > raises the exception. > > Thanks. > Simon > > On Wednesday, January 26, 2022 at 12:53:52 AM UTC+13 Simon King wrote:

Re: [sqlalchemy] SQL expression object expected, got object of type instead

2022-01-25 Thread Simon King
Can you show the part of *your* code that is triggering the error, and explain what you are trying to do? Plain python properties aren't normally very useful when accessed via a class. "Genome.attributes" returns a property object, not the return value from the function, and I don't understand

Re: [sqlalchemy] Re: How to add the index_elements to the on_conflict_do_update() method

2021-12-08 Thread Simon King
Does the table definition in postgres match your SQLAlchemy definition? Adding "unique=True" to the SQLAlchemy table definition will not automatically add an index to an existing table in the database. If you connect to the database using "psql" and run "\d message_symbol", does it show the

Re: [sqlalchemy] raise error on insert/update PK?

2021-11-19 Thread Simon King
You ought to be able to use the "sqlalchemy.func" system: https://docs.sqlalchemy.org/en/14/core/tutorial.html#functions server_default=sa.func.gen_random_uuid() Hope that helps, Simon On Fri, Nov 19, 2021 at 6:21 AM jens.t...@gmail.com wrote: > > Tim, > > I wanted to offload the UUID

Re: [sqlalchemy] Re: SqlAlchemy with Postgres: How can I make a query that checks if a string is in a list inside a json column

2021-10-19 Thread Simon King
For what it's worth, I think the "?" operator would work for this with JSONB, but not with JSON: postgres=# select '["user1", "user2"]'::jsonb ? 'user1'; ?column? -- t (1 row) postgres=# select '["user1", "user2"]'::jsonb ? 'user2'; ?column? -- t (1 row) postgres=# select

Re: [sqlalchemy] Using SQLAlchemy to check if column is in numeric ranges

2021-08-31 Thread Simon King
You want a combination of the "between" function/method: https://docs.sqlalchemy.org/en/14/core/sqlelement.html#sqlalchemy.sql.expression.between ...and the "or_" function: https://docs.sqlalchemy.org/en/14/core/sqlelement.html#sqlalchemy.sql.expression.or_ Something like this: ranges = [(18,

Re: [sqlalchemy] Join multiple tables with association tables

2021-08-10 Thread Simon King
It's difficult to tell from your code what your intention is. Is the relationship between Fact and Info meant to be many-to-many? And likewise the relationship between Text and Info? Forgetting SQLAlchemy for a moment, what is the SQL that you want to produce? Does the script below do what you

Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-30 Thread Simon King
I can think of a couple of options: 1. Create a TypeDecorator for String and Text columns that raises an error if it sees a bytestring. This will only flag the error when the session is flushed. 2. Listen for mapper_configured events, iterate over the mapper properties and add an

Re: [sqlalchemy] In the onupdate function, how to get the value of the row of records to be updated

2021-06-21 Thread Simon King
I don't think you'll be able to get what you want in an onupdate function. You'd probably be better off with the before_insert and before_update mapper events: https://docs.sqlalchemy.org/en/14/orm/events.html#sqlalchemy.orm.MapperEvents.before_insert

Re: [sqlalchemy] Revert multiple commits using a savepoint

2021-06-21 Thread Simon King
Which version of SQLAlchemy are you using, and how are you creating your engine? I believe savepoints are handled differently in SA 1.4 if you are using the "future-style" engine. Do these doc links help you at all?

Re: [sqlalchemy] Common datetime call

2021-06-18 Thread Simon King
On Fri, Jun 18, 2021 at 12:21 AM jca...@gmail.com wrote: > > Hi, > Does a means exist to generically call a local datetime func such that it > renders as SYSDATE in Oracle and GETDATE() in SQL Server? > > Thanks, > jlc > Do you need those functions explicitly? I think both databases support the

Re: [sqlalchemy] versioned_history example uses deprecated Column.copy() method

2021-06-17 Thread Simon King
ady many :) > > > > On Wed, Jun 16, 2021, at 7:15 AM, Simon King wrote: > > Hi all, > > I'm updating an app from SA 1.3 to 1.4 and getting a SADeprecationWarning: > > The Column.copy() method is deprecated and will be removed in a > future rele

[sqlalchemy] versioned_history example uses deprecated Column.copy() method

2021-06-16 Thread Simon King
Hi all, I'm updating an app from SA 1.3 to 1.4 and getting a SADeprecationWarning: The Column.copy() method is deprecated and will be removed in a future release. (deprecated since: 1.4) The code triggering the warning is based on the versioned_history example:

Re: [sqlalchemy] checking in

2021-06-15 Thread Simon King
You can see the archives at https://groups.google.com/g/sqlalchemy to get an idea of the traffic. Simon On Mon, Jun 14, 2021 at 10:25 PM Rich Shepard wrote: > > I've not worked with SQLAlchemy for several years but now want to use it in > a couple of applications. I've not seen messages on this

Re: [sqlalchemy] Postgresql JSON object update.

2021-05-24 Thread Simon King
You can use the "op" method: https://docs.sqlalchemy.org/en/14/core/sqlelement.html#sqlalchemy.sql.expression.Operators.op some_column.op("||")(other_column) Hope that helps, Simon On Mon, May 24, 2021 at 4:12 PM Massimiliano della Rovere wrote: > > In postgresql the || operator is the only

Re: [sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-05-07 Thread Simon King
chemy.ext.hybrid import hybrid_property >> >> class GeneralBeqReq(Base): >> ... >> @hybrid_property >> def is_id_valid(self): >> # some logic here >> if self.id % 3 == 0: >> return True >> else:

Re: [sqlalchemy] How to use user defined python function inside a sqlalchemy filter?

2021-04-28 Thread Simon King
Parameters that you pass to the Query.filter function are eventually going to be rendered into an SQL statement, so your is_id_valid function probably needs to return something built from SQLAlchemy's SQL expression language: https://docs.sqlalchemy.org/en/14/core/tutorial.html If you can explain

Re: Re[4]: [sqlalchemy] Invertinace mapped type_id to fix value for each child class

2021-04-13 Thread Simon King
TypID(): > > and to ensure only TypId exists fpr that type: > __mapper_args__ = { > "polymorphic_identity": ChildClass.TypID(), > } > > And as I said: Thanks a lot! > > SirAnn > > > -- Originalnachricht -- > Von: &q

Re: Re[2]: [sqlalchemy] Invertinace mapped type_id to fix value for each child class

2021-04-12 Thread Simon King
> venv\lib\site-packages\sqlalchemy\orm\mapper.py", line 1542, in > _configure_polymorphic_setter > self.polymorphic_on = self._props[self.polymorphic_on] > KeyError: 'typ_id' > > raise exception > sqlalchemy.exc.ArgumentError: Can't determine polymorphic_on value >

Re: [sqlalchemy] Invertinace mapped type_id to fix value for each child class

2021-04-12 Thread Simon King
I don't understand this comment: > I though on polymorphic_on, but I think that does not work because of the > fact that type_id ha a foreign key ... As far as I can tell, you ought to have this in the base class: __mapper_args__ = { 'polymorphic_on': typ_id } And this in the

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-24 Thread Simon King
) + tuple( > super_history_mapper.attrs.changed.columns > ) > So I added: > properties["accountable"] = (table.c.accountable,) + tuple( > super_history_mapper.attrs.accountable.columns > ) > > And the warnings have disappeared. > > Could you explain what the

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-24 Thread Simon King
ser with column > compound_administration_history.user under attribute 'user'. > Please configure one or more attributes for these same-named columns > explicitly. > > Thanks for your help resolving this, > > JP > On Tuesday, March 23, 2021 at 6:24:03 a.m. UTC-4 Simon Kin

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-23 Thread Simon King
ction: >> >> * User ID >> * Timestamp >> * Remote IP >> >> Using the sqlalchemy hooks, I'll then do something like: >> >> * update the object table with the user_transaction id >> or >> * use an association table that tracks a user_transaction_id to an obj

Re: [sqlalchemy] sqlalchemy get table with a string

2021-03-17 Thread Simon King
= db.Column(db.Integer,primary_key = True) > name = db.Column(db.String(80)) > password = db.Column(db.String(80)) > anaSayfa = db.Column(db.String(80)) > manuelSayfa = db.Column(db.String(80)) > dinamik = db.Column(db.String(80)) >

Re: [sqlalchemy] sqlalchemy get table with a string

2021-03-17 Thread Simon King
: > > I think we keep it in RAM in the first method, so it may be a problem if the > program is restarted. and I guess I don't understand what you mean by Base > class. > 17 Mart 2021 Çarşamba tarihinde saat 14:27:31 UTC+3 itibarıyla Simon King > şunları yazdı: >> >> T

Re: [sqlalchemy] sqlalchemy get table with a string

2021-03-17 Thread Simon King
There are lots of ways of doing this. One option is to provide a dictionary when creating your declarative_base: classes = {} Base = declarative_base(class_registry=classes) Now you can look up classes by name in that classes dictionary: def get_table_by_name(name): return

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-15 Thread Simon King
I use pyramid as a web framework, and when I create the DB session for each request, I add a reference to the current request object to the DB session. The session object has an "info" attribute which is intended for application-specific things like this:

Re: [sqlalchemy] Create Sqlalchemy ORM class from regular class gets "has no attribute ''_sa_instance_state''"

2021-03-15 Thread Simon King
I haven't followed your code in detail, but I think the problem might be here: clazz = school.Class('12', 'A') students = [ Student("Name1", "Sname1", clazz=clazz, code='aa7'), Student("Name2", "Sname2", clazz=clazz, code='bb7'), Student("Name3", "Sname3",

Re: [sqlalchemy] SQLAlchemy database record created on import of module

2021-03-15 Thread Simon King
I suggest you set up an event listener for the "after_attach" event on your session: https://docs.sqlalchemy.org/en/13/orm/events.html#sqlalchemy.orm.events.SessionEvents.after_attach Then you can set a breakpoint in the listener (or raise an exception, or use the traceback module to print a

Re: [sqlalchemy] Usage instructions for citext support not working

2021-02-15 Thread Simon King
Here's the error message: zsh: no matches found: sqlacodegen[citext] ie. this message is coming from your shell, not pip. Zsh treats the [...] part of the command as a filename pattern and tries to expand it: http://zsh.sourceforge.net/Doc/Release/Expansion.html#Filename-Generation To

Re: [sqlalchemy] SQLAlchemy (v.1.3.22) can not find Teradata engine inside Amazon Glue Job's script in Amazon environment

2021-02-04 Thread Simon King
ething about it. A big sorry for wasting your time and > thank you for an effort you did! > > BR, Anhelina > вторник, 2 февраля 2021 г. в 19:04:00 UTC+2, Simon King: >> >> SQLAlchemy uses setuptools entry points to load database drivers. >> Here's the definition for th

Re: [sqlalchemy] Creating column SQLAlchemy property on parent class based on child column property

2021-02-03 Thread Simon King
I don't think you're going to find a way to do that built in to SQLAlchemy. When you write "session.query(Parent)", SQLAlchemy constructs a query against the "parent" table. But to filter by your "is_done" property, it would suddenly need to join every child table into the query and construct a

Re: [sqlalchemy] SQLAlchemy (v.1.3.22) can not find Teradata engine inside Amazon Glue Job's script in Amazon environment

2021-02-02 Thread Simon King
SQLAlchemy uses setuptools entry points to load database drivers. Here's the definition for the teradata dialect: https://github.com/Teradata/sqlalchemy-teradata/blob/master/setup.py#L25 For that to work, you would normally have a directory called something like

Re: [sqlalchemy] Behaviour when setting a foreign key column.

2020-12-14 Thread Simon King
You have missed something important, but I don't know if it will clear up all your questions :-) In your example, c.company_id doesn't get populated until the first flush. Until then, c.company_id is None. So when you wrote: # Case 1: update the _id doesn't seem to reflect p.company_id =

Re: [sqlalchemy] conditionals inside column_property

2020-12-11 Thread Simon King
context of `select`. Is this considered a shorthand within > sqlalchemy? > > On Fri, Dec 11, 2020 at 2:16 AM Simon King wrote: >> >> You can do it, but you need to use an SQL conditional rather than a >> python one. In this case that would probably be a CASE expression

Re: [sqlalchemy] conditionals inside column_property

2020-12-11 Thread Simon King
You can do it, but you need to use an SQL conditional rather than a python one. In this case that would probably be a CASE expression: https://docs.sqlalchemy.org/en/13/core/sqlelement.html#sqlalchemy.sql.expression.case I think it would look something like this: from sqlalchemy.sql import case

Re: [sqlalchemy] Setting the FK not performed when relationship is declared

2020-12-10 Thread Simon King
I can't see anything obviously wrong with what you've written (you said "child.id is None", but I assume you meant child.parent_id). Can you provide a runnable example? Simon On Thu, Dec 10, 2020 at 8:27 AM Nikola Radovanovic wrote: > > Hi, > I have a FK in child pointing to parent table. Also,

Re: [sqlalchemy] object “is already present in this session” when using a new session with older objects

2020-11-23 Thread Simon King
I think your situation is described here: https://docs.sqlalchemy.org/en/14/orm/session_state_management.html#merge-tips I'm not certain, but my guess is that when you create westGate, you cause a *copy* of typeDict['gate'] to be merged into the current session (because the merge cascades across

Re: [sqlalchemy] NEED HELP! Using Hybrid property in SQLAlchemy filter throws error

2020-10-22 Thread Simon King
self.fabric_combination.append(fabric_combination) >> >> self.print_technique_id = print_technique.id >> self.print_technique.append(print_technique) >> >> self.design_number_id = design_number.id >> self.design_number.append(

Re: [sqlalchemy] NEED HELP! Using Hybrid property in SQLAlchemy filter throws error

2020-10-22 Thread Simon King
le. Simon On Thu, Oct 22, 2020 at 7:23 AM Padam Sethia wrote: > > Thanks for your input , the children have a many to many relationship with > the parent FinishedGoods , with this how would I refer to parent_id , do i > need to create and add that also ? > > On Wed, 21 Oct 20

Re: [sqlalchemy] NEED HELP! Using Hybrid property in SQLAlchemy filter throws error

2020-10-21 Thread Simon King
The "expression" part of a hybrid property is used whenever you write "FinishedGoodsParent.balance". It operates in the context of the class, not a single instance, and it needs to return an SQL expression that can be used inside a larger query. In your version, you are trying to iterate over

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-16 Thread Simon King
Yep, I misunderstood what setinputsizes was doing. I thought it told pyodbc how it should handle a particular datatype, rather than telling it how to handle the set of parameters it is about receive in the next execute() call... Sorry for adding to the confusion, Simon On Fri, Oct 16, 2020 at

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-15 Thread Simon King
ment varchar(max)properly? > > What would the argument be for not implementing varchar(max)in the pyodbc > dialect? > > On Thursday, October 15, 2020 at 11:05:32 AM UTC+2 Simon King wrote: >> >> You could call 'setinputsizes' in a handler for the >> 'before_cursor_execute' e

Re: [sqlalchemy] Cannot insert strings with a length greater than 2000 into columns with a datatype of Text, VARCHAR, or NVARCHAR using MS SQL Server 2017 and 2019

2020-10-15 Thread Simon King
You could call 'setinputsizes' in a handler for the 'before_cursor_execute' event, something like this: from sqlalchemy import event @event.listens_for(SomeEngine, 'before_cursor_execute') def receive_before_cursor_execute(conn, cursor, statement, parameters, context, executemany):

Re: [sqlalchemy] extend automapped classes with a mixin

2020-10-12 Thread Simon King
On Mon, Oct 12, 2020 at 6:59 PM Imran Akbar wrote: > > Hi, > > I'm using SQLAlchemy and am generating classes dynamically for my database > via the Automapping functionality. > > I need to add a Mixin class with various helper methods to each of these > automapped classes. > > I tried to create

Re: [sqlalchemy] ORM and objects with properties that need conversion to write to database

2020-10-08 Thread Simon King
On Thu, Oct 8, 2020 at 3:38 AM Richard Damon wrote: > > I am working on a app using SQLAlchemy's ORM layer to interface to the > database, but I am running into an issue that if an object has > 'complicated' property, like a UUID, that SQLAlchemy doesn't know how to > handle. One option would be

Re: [sqlalchemy] How can I use a composite foreign-key constraint with a "mixin" class using declarative?

2020-09-03 Thread Simon King
ySQL and SQLite), but that might not be the case for other > dialects like MSSQL? > > Best regards > Nicolas > > > > > > > > > Den tor. 3. sep. 2020 kl. 11.00 skrev Simon King : >> >> To be honest, I looked for documentation before I wrote my reply to

Re: [sqlalchemy] SQLAlchemy MYSQL query utf8 character problem

2020-09-03 Thread Simon King
On Thu, Sep 3, 2020 at 9:55 AM chat...@gmail.com wrote: > > Trying to query all items from a mysql (charset:utf8) table which has a field > that contains rows with chinese and other special characters I am taking the > above error > > items = session.query(Item).all() > > File >

Re: [sqlalchemy] How can I use a composite foreign-key constraint with a "mixin" class using declarative?

2020-09-03 Thread Simon King
vel foreign keys also just get ignored for > databases that don’t support them? > > In what scenarios would it make sense to use multiple modules, like I do? > > If possible, please provide a link to relevant part of the documentation, I’m > eager to learn more. > > Best w

Re: [sqlalchemy] How can I use a composite foreign-key constraint with a "mixin" class using declarative?

2020-09-01 Thread Simon King
Is __table_args__ the only reason why you are creating separate modules for the different databases? You can specify parameters for different database dialects in __table_args__, and the ones that don't match the current engine will be ignored. For example: import sqlalchemy as sa from

Re: [sqlalchemy] Getting column data from result set with column name as a string.

2020-08-20 Thread Simon King
If you want to get an attribute of an object where the name of the attribute is variable, you can use the getattr function: attrname = "lastname" column = getattr(User, attrname) for item in session.query(column): print(item) or: attrname = "lastname" for user in session.query(User):

Re: [sqlalchemy] Re: Deletion of a row from an association table

2020-08-15 Thread Simon King
SQLAlchemy normally presents a many-to-many relationship as a list on both sides. You've got "Machine.children", which is a list of Options, and "Option.parents", which is a list of Machines. If you remove one of the options from a machine.children list, you'll find that SQLAlchemy removes the

Re: [sqlalchemy] Flask SQlAlchemy BaseQuery Paginate not working correctly

2020-08-15 Thread Simon King
ed_at, > aggregates.created_by AS aggregates_created_by, aggregates.updated_at AS > aggregates_updated_at, aggregates.updated_by AS aggregates_updated_by > FROM aggregates JOIN aggregate_blocks ON aggregates.id = > aggregate_blocks.aggregate_id JOIN blocks ON blocks.id = > ag

Re: [sqlalchemy] Flask SQlAlchemy BaseQuery Paginate not working correctly

2020-08-14 Thread Simon King
"paginate" is not an SQLAlchemy function, so you'd be better off asking the author of whatever is providing that feature. However, I would guess that maybe paginate is naively applying something like "LIMIT 20" to the query. This doesn't work properly when you join along a one-to-many

Re: [sqlalchemy] Encrypt/Decrypt specific column(s)

2020-07-10 Thread Simon King
Not in the traditional sense, no. ORDER BY is implemented by the database, and with client-side encryption, the database only ever sees encrypted strings. Simon On Fri, Jul 10, 2020 at 8:41 AM Justin Van Vuuren wrote: > > Also, regarding the client side approach, would one be able to do an

Re: [sqlalchemy] convert subset to dictionary

2020-07-08 Thread Simon King
You should start by enabling SQLAlchemy logging to see the actual queries that are being run. The easiest way is to pass "echo=True" to your create_engine call. (You could also try echo="debug", but since you've got hundreds of thousands of rows you'll be swamped) Verify that the queries look

Re: [sqlalchemy] convert subset to dictionary

2020-07-07 Thread Simon King
tch the subjects using the with_entities option. > For some reason, this seems to work faster than using the > eager-loading/students.subjects/attribute_mapped_collection. They seem to > take 2 minutes longer than the above (what should be inefficient) approach. > > On Tuesday, 7

Re: [sqlalchemy] convert subset to dictionary

2020-07-07 Thread Simon King
elatively the same amount of time though. > > > On Friday, 3 July 2020 17:07:43 UTC+2, Simon King wrote: >> >> Are you eager-loading the "student.subjects" relationship? If not, >> that will give you the biggest performance increase. Without that, you >>

Re: [sqlalchemy] convert subset to dictionary

2020-07-03 Thread Simon King
__(self, code , value): > self.code = code > self.value = value > > > class Student(ResourceMixin, db.Model): > __tablename__ = 'students' > > subjects= db.relationship('Subject', backref='student') > > id = db.Column(db.Integer, pri

Re: [sqlalchemy] convert subset to dictionary

2020-07-03 Thread Simon King
Are you trying to optimise the database access (ie. minimize the number of queries), or provide a nice dictionary-style API for your Student objects? What do you mean when you say that looping over student.subjects is quite heavy? An association proxy can be used to get dict-style access to a

Re: [sqlalchemy] SQL injection

2020-07-02 Thread Simon King
ng sql >> injections? or can I use SQLAlchemy for that purpose >> I have tried to use the SQL penetration testing tools , but I am not happy >> with the results . Is there any way that I can generate SQL injections >> besides manual testing and pen testing . >> Any information is

Re: [sqlalchemy] SQL injection

2020-07-01 Thread Simon King
Hi, What do you mean by "SQL injection"? Thanks, Simon On Tue, Jun 30, 2020 at 10:12 PM Divya Shivakumar wrote: > > Hey how do i generate new sql injections from sqlalchemy . Any links or > information is much appreciated > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational

Re: [sqlalchemy] Re: how can i remove an entry from relational database using sqlalchemy in python

2020-05-29 Thread Simon King
It looks like you've got a many-to-many relationship between Contract and Permission, and you want to remove a Permission from a Contract (or vice versa). Is that right? If so, you can do something like this: contract = permission = contract.permissions.remove(permission)

Re: [sqlalchemy] Re: SQLAlchemy: UnicodeEncodeError: 'ascii' codec can't encode characters (db engine encoding ignored?)

2020-05-06 Thread Simon King
What are the values of "encoding" and "nencoding" on the connection object? https://github.com/oracle/python-cx_Oracle/issues/36 https://stackoverflow.com/a/37600367/395053 You probably need to grab the raw dbapi connection:

Re: [sqlalchemy] SQLAlchemy: UnicodeEncodeError: 'ascii' codec can't encode characters (db engine encoding ignored?)

2020-05-06 Thread Simon King
It might help to display the stack trace when the encoding fails, so we can see exactly where the error is coming from. Simon On Wed, May 6, 2020 at 9:01 AM Anno Nühm wrote: > > I am currently engaged in evaluating SQLAlchemy for a new project. When > trying to execute queries containing

Re: [sqlalchemy] looking for help building relationship that references an intermediate mixer table

2020-03-25 Thread Simon King
Do you need it to be an actual relationship? It's common to use an association proxy for this: https://docs.sqlalchemy.org/en/13/orm/extensions/associationproxy.html#simplifying-association-objects Hope that helps, Simon On Fri, Mar 20, 2020 at 7:47 PM Mark Aquino wrote: > > I'd like to

Re: [sqlalchemy] Cleaning metadata

2020-03-25 Thread Simon King
It's difficult to answer this question without knowing how your code is structured. Are you reflecting your tables from the database, or have you defined them statically? What is the full stack trace when you get those errors? Simon On Wed, Mar 25, 2020 at 10:27 AM Javier Collado Jiménez

Re: [sqlalchemy] SQLAlchemy URI (in superset) to connect to SSL enabled DRUI UI

2020-03-25 Thread Simon King
I've never used Druid, but this is really a question for the pydruid project, I don't know if any of those developers are on this list. It looks like pydruid only recently started supporting self-signed certificates (or allowing you to ignore certificate errors):

Re: [sqlalchemy] Bitwise AND operation in a select statement support in sqlalchemy

2020-02-25 Thread Simon King
SQLAlchemy overrides the & operator: https://docs.sqlalchemy.org/en/13/core/sqlelement.html#sqlalchemy.sql.expression.and_ You can use the "op" function to get at the postgres & operator: https://docs.sqlalchemy.org/en/13/core/sqlelement.html#sqlalchemy.sql.expression.ColumnElement.op

Re: [sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?

2020-02-14 Thread Simon King
On Fri, Feb 14, 2020 at 5:35 PM Mark Aquino wrote: > > I have a polymorphic class structure like this, with a lot of classes > extending the parent class. > In reality I'm using a Mixin that declares the visible_id column and it's > defined with @declared_attr.cascading, but for simplicity: > >

Re: [sqlalchemy] Re: SQL expression object expected, got object of type instead

2020-02-14 Thread Simon King
Can you show the real code that runs the query? I'm wondering whether the thing that you are comparing against my_table.c.name is not actually a simple string. Simon On Wed, Feb 12, 2020 at 11:01 PM Mark Wilkins wrote: > > Some additional code incase its relevent: > > # Get DB connection >

Re: [sqlalchemy] Bidirectional many-to-many without foreign key

2020-01-29 Thread Simon King
. > > On Tuesday, January 28, 2020 at 3:42:36 PM UTC, Simon King wrote: >> >> So conceptually, an address_id represents a *group* of addresses. A >> company can be associated with exactly one group of addresses, and one >> group of addresses can be shared by multipl

  1   2   3   4   5   6   7   >