Are you flushing the same session that was used to load the record?
What session does get_instance use?

Simon

On Mon, Aug 21, 2017 at 7:47 AM, pravin battula
<pravin.batt...@gmail.com> wrote:
> I did as below. But didn't work. Am i missing anything else.
>
> def update_record(session, id):
>     record_instance = get_instance(id)
>     if record_instance:
>         updateobj(record_instance, {'time_zone':'GMT','status':'done'})
>         session.flush()
>         session.commit()
>
> def updateobj(obj, data):
>     for key, value in data.items():
>         setattr(obj, key, value)
>
>
> On Friday, 18 August 2017 19:47:50 UTC+5:30, Simon King wrote:
>>
>> No, but you can trivially write your own function to do it:
>>
>> def updateobj(obj, data):
>>     for key, value in data.items():
>>         setattr(obj, key, value)
>>
>> Simon
>>
>> On Fri, Aug 18, 2017 at 3:14 PM, pravin battula
>> <pravin....@gmail.com> wrote:
>> > The solution which you gave will work but I have a dict of keys to be
>> > updated with that get instance. Is there any specific way of updating
>> > something like product_live_time_instance.update(data_dict).
>> >
>> >
>> > On Friday, 18 August 2017 19:21:12 UTC+5:30, Simon King wrote:
>> >>
>> >> On Fri, Aug 18, 2017 at 2:41 PM, pravin battula
>> >> <pravin....@gmail.com> wrote:
>> >> > Hi,
>> >> >
>> >> > I'm getting an instance of a model using a primary key like below.
>> >> > product_live_time = session.query(ProductLiveTime).get(product_id)
>> >> >
>> >> > Now, i want to update few columns using the same instance
>> >> > product_live_time,
>> >> > how can i do it without doing filter again like below i.e
>> >> > session.query(ProductLiveTime).filter(ProductLiveTime.product_id ==
>> >> > product_id).update(data).
>> >> > is there any other better way of doing it.
>> >> >
>> >>
>> >> Maybe I'm misunderstanding the question, but:
>> >>
>> >> product_live_item.attr1 = value1
>> >> product_live_item.attr2 = value2
>> >> session.flush()
>> >>
>> >> Is that what you meant?
>> >>
>> >> Simon
>> >
>> > --
>> > 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+...@googlegroups.com.
>> > To post to this group, send email to sqlal...@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/sqlalchemy.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 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 - 
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 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.

Reply via email to