[sqlalchemy] ArgumentError: Only one Column may be marked autoincrement=True, found both id and id

2020-08-21 Thread Vitaly Kruglikov
Dear all,

I am using:
sqlalchemy==1.3.18
psycopg2==2.8.4
connection url schema: "postgresql+psycopg2://..."
postgres 10.x

when I define an explicit AutomapBase-derived model for 
'sqa_global_context'  table with only the primary key, I expected that 
running `Base.metadata.reflect(bind=database.ENGINE, 
only=['sqa_global_context']); Base.prepare()` would backfill missing 
columns and relationships in that table. However, after running 
`Base.prepare(engine, reflect=True)`, the missing columns and relationships 
are not populated in my table.

My code looks like this:

```
_AutomapBase = automap.automap_base()

class Model1(_AutomapBase):
__tablename__ = 'model1"

id_ = sa.Column('id', sa.Integer, primary_key=True, autoincrement=True,
   key='id_')
tag = sa.Column(sa.String())

_AutomapBase.metadata.reflect(bind=ENGINE, only=['model1'], 
extend_existing=True)
_AutomapBase.prepare()
```

I get the exception `ArgumentError: Only one Column may be marked 
autoincrement=True, found both id and id.` when I run the following insert:
```
row = Model1(tag='tag1')
orm_session.add(attempt)
orm_session.flush()
```

I suspect this has something to do with the combination of the explicit 
definition of the `id_` column and reflection, but don't know how to fix. I 
really need to keep the explicit `id_` descriptor and shouldn't rename it 
to `id` because that's a reserved python word.

Please help. Many thanks in advance!


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/426d0281-27ee-448d-829f-72f137532fd2n%40googlegroups.com.


[sqlalchemy] declared_attr not working with Postgres HSTORE

2020-08-21 Thread Saakshaat Singh
Hi,

I'm working with SQLAlchemy and Postgres and I have a polymorphic model 
whose subclasses have a field with the same name. To allow this field to 
co-exist with the others and not cause any name conflicts, I'm using the 
`declare_attr` decorator from SQLAlchemy. 

This solution works well for fields consisting of primary data types, 
however when I try to use Postgres's HSTORE to store dictionary values, 
SQLAlchemy complains with:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt 
type 'dict'


My guess is that this happens because `declared_attr` has constrains on 
which data types its fields have.

Here's an example of how my models look:

*import enum *

*import sqlalchemy as sa*
*from sqlalchemy.dialects.postgres import ARRAY, HSTORE*
*from sqlalchemy.ext.mutables import MutableDict*

*class ChildType(enum.Enum):*
*sub_1 = "sub_1"*
*sub_2 = "sub_2"*
*sub_3 = "sub_3"*

*class ParentModel(sa.declarative_base()):*
*__table__ = 'parent'*
*general_field = sa.Column(sa.String)*
*r_type = sa.Column(sa.Enum(ChildType))*

*__mapper_args__ = {*
*'polymorphic_identity': 'parent',*
*'polymorphic_on': resource_type*
*}*


*class Sub1(ParentModel):*
*@sa.declared_attr*
*def child_value(cls):*
*return ParentModel.__table__.c.get('child_value', 
sa.Column(sa.Integer, nullable=True))*

*__mapper_args__ = {*
*'polymorphic_identity': ChildType.sub_1*
*}*

*class Sub2(ParentModel):*
*@sa.declared_attr*
*def child_value(cls):*
*return ParentModel.__table__.c.get('child_value', 
sa.Column(sa.Boolean, nullable=True))*

*__mapper_args__ = {*
*'polymorphic_identity': ChildType.sub_2*
*}*

*class Sub3(ParentModel):*
*@sa.declared_attr*
*def child_value(cls):*
*return ParentModel.__table__.c.get('child_value', 
sa.Column(ARRAY(MutableDict.as_mutable(HSTORE*

*__mapper_args__ = {*
*'polymorphic_identity': ChildType.sub_3*
*}*


Can anyone help me out with a potential workaround/solution?

Thanks!

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/0421937b-08f0-470d-8067-43430bfc1ca8n%40googlegroups.com.


Re: [sqlalchemy] Download documentation as pdf

2020-08-21 Thread Mike Bayer
it's not, as PDF generation is very problematic and we are not able to provide 
this file.

The sphinx documentation can be built as LaTeX that can then be converted to 
pdf but you'd find it's a very error prone process, and the resulting PDF 
doesn't look very good either.

On Fri, Aug 21, 2020, at 11:19 AM, Amey Joshi wrote:
> I am curious, is 1.3 documentation available as pdf format ?  I can see it is 
> available as zip file as a bundle of html files 
> https://docs.sqlalchemy.org/en/13/index.html.
> 
> Amey
> 

> --
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/
>  
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/CADZgw7XFCnL0PTKx%2BbJTkThQZd6g5EuZePpRb9wXd9_vpJc76w%40mail.gmail.com
>  
> .

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/60f9a89e-3e08-40d2-a67d-4efe09d1215e%40www.fastmail.com.


[sqlalchemy] Download documentation as pdf

2020-08-21 Thread Amey Joshi
I am curious, is 1.3 documentation available as pdf format ?  I can see it
is available as zip file as a bundle of html files
https://docs.sqlalchemy.org/en/13/index.html.

Amey

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CADZgw7XFCnL0PTKx%2BbJTkThQZd6g5EuZePpRb9wXd9_vpJc76w%40mail.gmail.com.


[sqlalchemy] Re: AttributeError: 'NoneType' object has no attribute 'pop'

2020-08-21 Thread ling...@gmail.com
AttributeError means that there was an Error that had to do with an 
Attribute request. In general, when you write x.y, y is the purported 
attribute of x. NoneType means that instead of an instance of whatever 
Class or Object you think you're working with, you've actually got None 
. That usually means 
that an assignment or function call up failed or returned an unexpected 
result.

mylist = mylist.sort()

The sort() method of a list sorts the list in-place, that is, mylist is 
modified. But the actual return value of the method is None and not the 
list sorted. So you've just assigned None to mylist. If you next try to do, 
say, mylist.append(1) Python will give you this error.



On Tuesday, November 11, 2008 at 6:58:41 AM UTC+5:30 arashf wrote:

> Traceback (most recent call last):
> File "/srv/server/metaserver/metaserver/lib/base.py", line 56, in
> __call__
> ret = WSGIController.__call__(self, environ, start_response)
> File "/usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/pylons/
> controllers/core.py", line 195, in __call__
> after = self._inspect_call(self.__after__)
> wasn't getting this on the betas of sqlalchemy, but am getting it on
> rc3. any ideas?
>
> File "/usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/pylons/
> controllers/core.py", line 79, in _inspect_call
> result = func(**args)
> File "/srv/server/metaserver/metaserver/lib/base.py", line 96, in
> __after__
> metaserver.model.Session.commit()
> File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
> sqlalchemy/orm/scoping.py", line 121, in do
> return getattr(self.registry(), name)(*args, **kwargs)
> File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
> sqlalchemy/orm/session.py", line 670, in commit
> self.transaction.commit()
> File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
> sqlalchemy/orm/session.py", line 385, in commit
> self._remove_snapshot()
> File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
> sqlalchemy/orm/session.py", line 306, in _remove_snapshot
> _expire_state(s, None)
> File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
> sqlalchemy/orm/attributes.py", line 985, in expire_attributes
> self.dict.pop(key, None)
> AttributeError: 'NoneType' object has no attribute 'pop'

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/0015b592-77c1-4161-b7da-bd23f72a7023n%40googlegroups.com.