Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLAlchemy Session add() return value

working on pyramid with sqlalchemy:

newjob_obj=Job(name=name,job_propery=job_property,sizeX=sizeX,
    sizeY=sizeY,quantity=quantity,timeline=timeline,
    description=description,remarks=remarks,
    client_id=client_id,created_by=created_by,status=status
)
new_job=session.add(newjob_obj)
print('Return newJob value %s\n' % new_job)

Here new_job is printing as None. add function of session returns object or not. Please help.

like image 672
Pravin Reddy Avatar asked Oct 15 '13 18:10

Pravin Reddy


1 Answers

To answer your question in the comment of @mark's answer - in order to receive your "inserted ID" after the commit:

session.add(newjob_obj)
session.commit()

You should refresh the inserted object with:

session.refresh(newjob_obj)
print newjob_obj.id

Hope it helps ..

like image 131
Ricky Levi Avatar answered Sep 30 '22 17:09

Ricky Levi