[sqlalchemy] No inspection system is available for object of type

2016-04-18 Thread 刘邦瑞
Hi,

I encountered this problem when I try to use Automap methods in Graphene.

The situation is: I have an existing table 'cb_people' in MySQL databases 
under SCHEMA_NAME and want to auto map it to python class People like this:


engine = create_engine('mysql+mysqldb://root:sync@localhost', 
convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, 
bind=engine))
metadata = MetaData()
metadata.reflect(bind = engine, schema = SCHEMA_NAME)
Base = automap_base(metadata = metadata)
Base.query = db_session.query_property()

class People(Base):
__tablename__ = 'cb_people'
id = Column(Integer, primary_key=True)
object_id = Column(String(64), nullable=False)
first_name = Column(String(128), nullable=False)
last_name = Column(String(128), nullable=False)
birthplace = Column(String(128), nullable=True)
affiliation_name = Column(String(128), nullable=True)

def init_db():
Base.prepare(engine, reflect=True, classname_for_table = 'cb_people')
People = Base.classes.cb_people


Then I need to register the class People on graphene like this:


@schema.register
class People(SQLAlchemyNode):
class Meta:
 model = PeopleModel


which is not correct. When I run the function init_db(), I got the error 
message:


File "/Users/dennisliu/Documents/CrunchbaseFAQ/flask_sqlalchemy/schema.py", 
line 12, in 

class People(SQLAlchemyNode):

  File 
"/usr/local/lib/python2.7/site-packages/graphene/core/classtypes/base.py", 
line 31, in __new__

return mcs.construct(new_class, bases, attrs)

  File 
"/usr/local/lib/python2.7/site-packages/graphene/contrib/sqlalchemy/types.py", 
line 57, in construct

cls.construct_fields()

  File 
"/usr/local/lib/python2.7/site-packages/graphene/contrib/sqlalchemy/types.py", 
line 22, in construct_fields

inspected_model = sqlalchemyinspect(cls._meta.model)

  File "build/bdist.macosx-10.11-x86_64/egg/sqlalchemy/inspection.py", line 
75, in inspect

sqlalchemy.exc.NoInspectionAvailable: No inspection system is available for 
object of type 



Is there anyway to solve this problem?

Thank you so much!



Best,

Bangrui



-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] NoSuchColumnError happens when multiple processes concurrently access to a row with locking

2016-04-18 Thread Shingo Toda
Hi all

I am now seeing the SQLAlchemy raise 'NoSuchColumnError' occasionally when 
concurrent accesses happen with 'select for update'.

My application uses
* SQLAlchemy 0.8.4
* MySQL-python 1.2.3
* CentOS6.7
* python 2.6
* MariaDB 10.0.20 (three-node Galera Cluster with haproxy 1.5.2)

I know Galera does not support explicit lock so I configure haproxy to 
redirect incoming requests only to one active node.
The reason of this is to make explicit locking work for 'select for 
update', like the way we use single database server.
So the other Galera nodes are setup just for backup.

To break down what that application does, firstly I create engine and 
sessioinmaker with isolation_level="READ COMMITTED"

```
import sqlalchemy
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool

# 192.168.0.2 is virtual IP
engine = sqlalchemy.create_engine(
"mysql://test:testtest@192.168.0.2/test",
poolclass=NullPool,
isolation_level="READ COMMITTED")
maker = sessionmaker(bind=engine, autocommit=True)
```

Secondary the model is defined below, which has a composite key 
(`data_id1`, `data_id2`).

```
Base = declarative_base()
class MyData(Base):
__tablename__ = 'mydata'
__table_args__ = (
UniqueConstraint('data_id1', 'data_id2'),
)
data_id1 = Column(String(64), primary_key=True)
data_id2 = Column(String(64), primary_key=True)
status = Column(String(40), nullable=True)
```

There could be multiple application processes running(not daemon) which 
could access to the same record.
Each process firstly tries to lock a row, then check status of MyData and 
update status attribute.

```
.
session.begin()
try:
mydata = get_mydata(session, data_id1, data_id2, lockmode="update")
// do something here to check status
update_status(session, data_id1, data_id2, "some status")
session.commit()
except Exception as e:
session.rollback()
.


def get_mydata(session, data_id1, data_id2, lockmode=None):
query = 
session.query(MyData).filter_by(data_id1=data_id1).filter_by(data_id2=data_id2)
if lockmode:
query = query.with_lockmode(lockmode)
return query.first()


def update_status(session, data_id1, data_id2, status):
data = get_mydata(session, data_id1, data_id2)
data.status = status
session.flush()
```

When concurrent access happens and one process locks a row, subsequent 
processes are blocked from processing the same record at the same time.
The subsequent processes will wait until the previous one releases the lock.
This usually works fine as I expect but sometimes I see `NoSuchColumnError` 
cast when the subsequent process call `query.first()` within 
`update_status()`.

```
Traceback (most recent call last):
  File "/root/myapp.py", line 301, in some_func()
update_status(session, data_id1, data_id2, "some status")
  File "/root/myapp.py", line 231, in update_status
data = get_mydata(session, data_id1, data_id2)
  File "/root/myapp.py", line 256, in get_mydata
return query.first()
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/query.py", line 
2282, in first
ret = list(self[0:1])
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/query.py", line 
2149, in __getitem__
return list(res)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/loading.py", line 
72, in instances
rows = [process[0](row, None) for row in fetch]
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/loading.py", line 
356, in _instance
tuple([row[column] for column in pk_cols])
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/result.py", 
line 314, in _key_fallback
expression._string_or_unprintable(key))
NoSuchColumnError: "Could not locate column in row for column 
'mydata.data_id1'"
```

I wish someone knows which point causes this error.

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Posting SQLAlchemy-Continnum related posts to this group?

2016-04-18 Thread Mike Bayer


I try to discourage posts about other projects here only because it is 
often the case that the maintainers of those projects aren't being 
responsive to user issues, so posting here seeks to take advantage of 
the extremely high level of responsiveness we have here.  However we 
really can't handle the workload of *other* projects too.


Now if the maintainer of SQLAlchemy-Continuum wants to use this list to 
talk about things, and they can handle those support requests, that's 
not a big deal.   If we put [sqlalchemy-continuum] in the header we can 
just have those posts sitting out here for people who are interested to 
help out.   I should likely just make this a new policy.


On 04/18/2016 09:23 AM, Piotr Dobrogost wrote:

Hi!

Is it allowed to post questions regarding SQLAlchemy-Continuum's
extension to SQLAlchemy to this group?
I raised related issue at
https://github.com/kvesteri/sqlalchemy-continuum/issues/138


Regards,
Piotr Dobrogost

--
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 post to this group, send email to sqlalchemy@googlegroups.com
.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Posting SQLAlchemy-Continnum related posts to this group?

2016-04-18 Thread Piotr Dobrogost
Hi!

Is it allowed to post questions regarding SQLAlchemy-Continuum's extension 
to SQLAlchemy to this group?
I raised related issue at 
https://github.com/kvesteri/sqlalchemy-continuum/issues/138


Regards,
Piotr Dobrogost

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.