Column vs InstrumentedAttribute

471 views
Skip to first unread message

Val Huber

unread,
Feb 23, 2023, 7:36:11 PM2/23/23
to sqlalchemy
Hello, All

In SQLAlchemy 1.4.29, the I get the warnings shown in the attached screen shot.  These are calls to LogicBank; if I alter LogicBank to use Column instead of InstrumentedAttribute, it fails with 

AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Customer.Balance has an attribute 'descriptor'

I don't believe I got these warnings with SQLAlchemy 1.3.

Suggestions?

Thanks,
Val


Column vs InstumentedAttribute.png

Val Huber

unread,
Feb 23, 2023, 10:22:21 PM2/23/23
to sqlalchemy
The target function looks like this:

class Rule:
"""Invoke these functions to declare rules.

Rules are *not* run as they are defined,
they are run when you issue `session.commit()'.

.. _Rule Summary:

Use code completion to discover rules and their parameters.
"""

@staticmethod
def sum(derive: InstrumentedAttribute, as_sum_of: any, where: any = None, child_role_name: str = ""):
"""
Derive parent column as sum of designated child column, optional where

Example
Rule.sum(derive=models.Customer.Balance, as_sum_of=models.Order.AmountTotal,
where=Lambda row: row.ShippedDate is None)

Optimized to eliminate / minimize SQLs: Pruning, Adjustment Logic

Args:
derive: name of parent <class.attribute> being derived
as_sum_of: name of child <class.attribute> being summed
child_role_name: parent's child accessor attribute (required only for disambiguation)
where: optional where clause, designates which child rows are summed


"""
return Sum(derive, as_sum_of, where, child_role_name)




The model is declared like this:

class Customer(SAFRSBase, Base):
__tablename__ = 'Customer'
_s_collection_name = 'Customer'
__bind_key__ = 'None'

Id = Column(String(8000), primary_key=True)
CompanyName = Column(String(8000))
Balance = Column(DECIMAL)

Mike Bayer

unread,
Feb 23, 2023, 10:39:45 PM2/23/23
to noreply-spamdigest via sqlalchemy
those are typing issues being reported by Pylance and do not affect the runtime behavior of the application.

Pylance refers to typing stubs for SQLAlchemy 1.4 which don't apply to SQLAlchemy 1.3.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

Attachments:
  • Column vs InstumentedAttribute.png

Val Huber

unread,
Feb 23, 2023, 10:56:41 PM2/23/23
to sqlal...@googlegroups.com
Yes, Mike, I agree -  definitely seeing correct runtime behavior.

Just looking to get past the somewhat scary alerts (which, btw, do not occur in PyCharm).  Care and feeding of the IDE, I suppose…

Not super urgent, but would be good to clear up...

You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/qwj30TCnqzQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/9c0cedf3-434d-489b-8e60-a9ef68324df1%40app.fastmail.com.

Mike Bayer

unread,
Feb 24, 2023, 12:08:08 AM2/24/23
to noreply-spamdigest via sqlalchemy
your "derive" argument would need to be opened up to accept ColumnElement.

if you are going for being fully typed like this you would do way better by targeting 2.0 instead of 1.4.  the typing in 1.4 is nor very good and also not compatible with that of 2.0.
Reply all
Reply to author
Forward
0 new messages