SQLAlchemy (1.0.8)

On Friday, September 15, 2017 at 12:14:33 PM UTC-4, Conferency wrote:
>
> class Paper(db.Model):
>     __tablename__ = 'papers'
>     reviewers = db.relationship('User', secondary=paper_reviewer,
>                                 backref=db.backref('papers_reviewed',
>                                                    lazy='dynamic'),
>                                 lazy='dynamic')
>
> paper_reviewer = db.Table('paper_reviewer',
>                           db.Column('user_id', db.Integer,
>                                     db.ForeignKey('users.id'),
>                                     primary_key=True),
>                           db.Column('paper_id', db.Integer,
>                                     db.ForeignKey('papers.id'),
>                                     primary_key=True)
>                           )
> @event.listens_for(Paper.reviewers, 'append')def 
> paper_reviewers_append(target, value, initiator):
>     # select queries...
>     
>
>
> paper.reviewers.append(usr)
> db.session.add(paper)
> db.session.commit()
>
> The listener is fired before the execution of paper.reviewers.append(usr). 
> The execution of append makes two insertions into paper_reviewer table. The 
> second one causes IntegrityError: UNIQUE constraint failed.
>
> I tried different operations in the listener. If the operation in listener 
> triggered any query, the IntegrityError would be caused while the commit() 
> was executed. Not sure why listener could cause this error. Can anyone give 
> me some details? Plz
>
>

-- 
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