Help with SQLAlchemy

41 views
Skip to first unread message

Biswas, Pinakee

unread,
Apr 13, 2013, 6:12:07 AM4/13/13
to pylons-...@googlegroups.com

Hi,

 

I need help with SQLAlchemy. I am not sure if this is the right forum to ask the query but since we are using Pylons and SQLAlchemy is part of the same, I thought asking here:

 

I am using UPDATE query on SQLAlchemy session as follows:

 

p = DBSession.query(Paymenttransaction).filter_by(id = payment.id).update({"status":'success', "transactionid":’transaction_id’]}, synchronize_session=False)

 

p is returning 1 (number of rows matching the query). There is also no exception thrown. But somehow the columns are not getting updated in the Database. I am not sure what is going wrong here.

 

I have used similar query elsewhere in the code where it is working fine.

 

Would really appreciate if you could give me some pointers.

 

We are using SQLAlchemy 0.6. Database is MySQL.

 

Looking forward to your response and support…

 

Thanks,

Pinakee Biswas

Director & CTO

 

cid:E95B8D36-1F36-4B11-B91A-CF8977B83894

 

7E- Mail: pin...@vvidiacom.com I 8Web: http://www.vvidiacom.com

 

image001.jpg
image002.png

Laurent DAVERIO

unread,
Apr 13, 2013, 6:43:49 AM4/13/13
to pylons-...@googlegroups.com
Hi,

> I need help with SQLAlchemy. I am not sure if this is the right forum to
> ask the query but since we are using Pylons and SQLAlchemy is part of
> the same, I thought asking here:

No, it's probably not the right forum, as SQLAlchemy is a dependency,
not a part of Pylons (no more than Python, or Linux, are) :-)

> p is returning 1 (number of rows matching the query). There is also no
> exception thrown. But somehow the columns are not getting updated in the
> Database. I am not sure what is going wrong here.

Have you tried adding an explicit DBSession.commit()? Pyramid doesn't
require it - or, rather, doesn't allow for it, since it already uses an
transaction manager - but if I remember correctly, Pylons has no
automatic transaction manager.

> Would really appreciate if you could give me some pointers.

You could also activate SQL query logging (from the development.ini
file), so that you can make sure that the query is effectively passed
to MySQL.

Best of luck,

Laurent.

Werner

unread,
Apr 13, 2013, 6:46:33 AM4/13/13
to pylons-...@googlegroups.com
Hi,

I don't use Pylons (at least not yet), but use SA.


On 13/04/2013 12:12, Biswas, Pinakee wrote:

Hi,

 

I need help with SQLAlchemy. I am not sure if this is the right forum to ask the query but since we are using Pylons and SQLAlchemy is part of the same, I thought asking here:

 

I am using UPDATE query on SQLAlchemy session as follows:

 

p = DBSession.query(Paymenttransaction).filter_by(id = payment.id).update({"status":'success', "transactionid":’transaction_id’]}, synchronize_session=False)

 

p is returning 1 (number of rows matching the query). There is also no exception thrown. But somehow the columns are not getting updated in the Database. I am not sure what is going wrong here.

Is there a commit after this?

If you activate logging on your DBSession you should be able to see this.

 

I have used similar query elsewhere in the code where it is working fine.

 

Would really appreciate if you could give me some pointers.

 

We are using SQLAlchemy 0.6.

This is a very very very old version of SQLAlchemy, any reason why you don't use 0.8?

Werner

León Domingo

unread,
Apr 13, 2013, 8:57:04 AM4/13/13
to pylons-...@googlegroups.com
Hi,
I have a similar problem and I've found out one thing.

If I insert or update using Table (schema.Table) changes are not committed to the database.

dbs = DBSession

meta = MetaData(bind=dbs.bind)
table = Table('foo', autoload=True)

dbs.execute(table.update(dict(foo_id=1), values=dict(bar='bar'))
dbs.commit()

But If I use a "declarative_base" class and I make a "fake" change like:

meta = MetaData(bind=dbs.bind)
table = Table('foo', autoload=True)

dbs.execute(table.update(dict(foo_id=1), values=dict(bar='bar'))

o = dbs.query(AClass).get(1)
o.id = o.id
dbs.add(o)
dbs.commit()

Then all the changes are commited to the database. May be the "first" change doesn't change the "dirty state" of the session. I don't know.

Regards,
León

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Biswas, Pinakee

unread,
Apr 13, 2013, 10:22:45 AM4/13/13
to Laurent DAVERIO, pylons-...@googlegroups.com
Hi Laurent,

Thanks for your response.

I think I have tried with commit also but I will try again. But do we need to commit after every query? I do not think I am doing commit after other queries but still they are working.

I will check logging.

Thanks,
Pinakee Biswas
Director & CTO



DGSM Mobile (Voice & Data): +91-982-016-7979
GTel: +91-22-26733737 I IFax:+91-22-26732828
FE- Mail: pin...@vvidiacom.com I IWeb: http://www.vvidiacom.com


 Please don't print this e-mail unless you really need to, this will preserve trees on planet earth.
----------------------------Disclaimer-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The information contained in this message (including any attachments) is confidential and may be privileged. If you have received it by mistake please notify the sender by return e-mail and permanently delete this message and any attachments from your system. Please note that e-mails are susceptible to change and malwares. VVIDIA COMMUNICATIONS PVT LTD. (including its group companies) shall not be liable for the improper or incomplete transmission of the information contained in this communication nor for any delay in its receipt or damage to your system.
-------------------------------------------------------------------------------------------------------------------------Disclaimer----------------------------------------------------------------------------------------------------------

-----Original Message-----
From: Laurent DAVERIO [mailto:lau...@daverio.net]
Sent: 13 April 2013 16:11
To: pylons-...@googlegroups.com
Cc: Biswas, Pinakee
Subject: Re: Help with SQLAlchemy

Hi,

> I need help with SQLAlchemy. I am not sure if this is the right forum
> to ask the query but since we are using Pylons and SQLAlchemy is part
> of the same, I thought asking here:

No, it's probably not the right forum, as SQLAlchemy is a dependency, not a part of Pylons (no more than Python, or Linux, are) :-)

> p is returning 1 (number of rows matching the query). There is also no
> exception thrown. But somehow the columns are not getting updated in
> the Database. I am not sure what is going wrong here.

Have you tried adding an explicit DBSession.commit()? Pyramid doesn't require it - or, rather, doesn't allow for it, since it already uses an transaction manager - but if I remember correctly, Pylons has no automatic transaction manager.

> Would really appreciate if you could give me some pointers.

Biswas, Pinakee

unread,
Apr 13, 2013, 10:24:50 AM4/13/13
to pylons-...@googlegroups.com

Hi Werner,

 

Thanks for your response.

 

We have been using 0.6 for quite sometime. Would there be lot of changes while upgrading to 0.8? We would need to plan accordingly.

 

Thanks,

Pinakee Biswas

Director & CTO

 

cid:E95B8D36-1F36-4B11-B91A-CF8977B83894

 

7E- Mail: pin...@vvidiacom.com I 8Web: http://www.vvidiacom.com

 

 

From: pylons-...@googlegroups.com [mailto:pylons-...@googlegroups.com] On Behalf Of Werner
Sent: 13 April 2013 16:17
To: pylons-...@googlegroups.com
Subject: Re: Help with SQLAlchemy

 

Hi,

--

image001.jpg
image002.png

Werner

unread,
Apr 13, 2013, 12:11:37 PM4/13/13
to pylons-...@googlegroups.com
Hi,


On 13/04/2013 16:24, Biswas, Pinakee wrote:

Hi Werner,

 

Thanks for your response.

 

We have been using 0.6 for quite sometime. Would there be lot of changes while upgrading to 0.8? We would need to plan accordingly.

I am no expert but moved up on each major release without any real issues - but you should allow enough time and plan for it.

See here:
http://docs.sqlalchemy.org/en/rel_0_7/changelog/migration_07.html
http://sqlalchemy.readthedocs.org/en/rel_0_8/changelog/migration_08.html

Werner

Andi Balke

unread,
Apr 13, 2013, 2:29:02 PM4/13/13
to pylons-...@googlegroups.com
just guessing, but this seems wrong: ``filter_by(id = payment.id)``. shouldn't it be ``filter_by(id == payment.id)``?

andi

(sent right out of my head)

On 13.04.2013, at 12:12, "Biswas, Pinakee" <pin...@vvidiacom.com> wrote:

Hi,

 

I need help with SQLAlchemy. I am not sure if this is the right forum to ask the query but since we are using Pylons and SQLAlchemy is part of the same, I thought asking here:

 

I am using UPDATE query on SQLAlchemy session as follows:

 

p = DBSession.query(Paymenttransaction).filter_by(id = payment.id).update({"status":'success', "transactionid":’transaction_id’]}, synchronize_session=False)

 

p is returning 1 (number of rows matching the query). There is also no exception thrown. But somehow the columns are not getting updated in the Database. I am not sure what is going wrong here.

 

I have used similar query elsewhere in the code where it is working fine.

 

Would really appreciate if you could give me some pointers.

 

We are using SQLAlchemy 0.6. Database is MySQL.

 

Looking forward to your response and support…

 

Thanks,

Pinakee Biswas

Director & CTO

 

<image001.jpg>

<image002.png>

 

Jonathan Vanasco

unread,
Apr 13, 2013, 3:48:45 PM4/13/13
to pylons-discuss
> just guessing, but this seems wrong: ``filter_by(id = payment.id)``. shouldn't it be ``filter_by(id == payment.id)``?

`filter_by` expects kw args ( `=` )
`filter` expects args/expressions ( `==` )

http://stackoverflow.com/questions/2128505/whats-the-difference-between-filter-and-filter-by-in-sqlalchemy
Reply all
Reply to author
Forward
0 new messages