im not totally familiar with turbogears configuration, so heres some  
questions:

1. we're using straight sqlalchemy.mods.threadlocal , and thats how  
youre getting 'objectstore', right ?
2. is the session cleared out before each request begins ?  what  
happens if you say "print [s for s in  
sa.objectstore.context.current]" at the top of the request, before  
youve loaded anything ? (note to self, make the objectstore interface  
more like a Session....)

actually, just #2 might shed some light....if thats really the code,  
then seems like there has to be something still in the session  
getting saved.  keep in mind that becasue youre using 'threadlocal',  
any time a ReviewQuestionAnswer object gets created, it gets stuck in  
the current thread's session.  if you can limit your app to not  
create any ReviewQuestionAnswer objects, put a "raise" inside its  
constructor, which will nail down where its getting created.

FWIW, this is one advantage to the newer 0.2 model of not having any  
thread local anything.  if you modify your app to work that way, you   
would probably not have this kind of problem since everything needs  
to be explicitly save()d.

On Jul 24, 2006, at 5:19 PM, jeff emminger wrote:

> i have a Review object which has associated ReviewQuestionAnswer
> objects... randomly during updates, it seems that SA wants to issue an
> insert into the review_question_answers table.  nowhere in my code am
> i creating new answer objects to be inserted.
>
> i'm using an oracle database and turbogears
>
> sorry i can't provide a concrete example to recreate it, since it
> happens sporadically... below is the code that is doing it
>
>
> reviews = Table(
>     "reviews", metadata,
>     Column("id", Integer, Sequence('reviews_seq'), primary_key=True),
>     Column("something", Unicode(255), nullable=False),
>     Column("other", Unicode(255), nullable=False)
> )# end reviews Table
>
> review_question_answers = Table(
>     "review_question_answers", metadata,
>     Column("id", Integer, Sequence('review_question_answers_seq'),
> primary_key=True),
>     Column("review_id", Integer, ForeignKey("reviews.id"),  
> nullable=False),
>     Column("question_id", Integer, ForeignKey("review_questions.id"),
> nullable=False),
>     Column("answer", Unicode(255), nullable=True),
> )# end review_question_answers Table
>
> model:
> =====
> class ReviewQuestionAnswer(object): pass
> ReviewQuestionAnswer.mapper = mapper(ReviewQuestionAnswer,
> review_question_answers)
>
> class Review(object): pass
> Review.mapper = mapper(Review, reviews,
>     properties=dict(
>         answers=relation(ReviewQuestionAnswer.mapper, lazy=True,  
> private=True)
>     )
> )
>
> controller:
> ==========
>  sess = sa.objectstore
>  tx = sess.create_transaction()
>
>  # update the review's editable fields
>  review = sess.query(model.Review).get_by(id=id)
>  review.something = kw.get('something', None)
>  review.other = kw.get('other', None)
>
>  # update the answers
>  for answer in review.answers:
>               answer.answer = kw['answer_%s' % answer.question_id]
>
>  tx.commit()
>
> i'll get output on the console during the attempt like so:
> [2006-07-24 17:06:06,243] [engine]: UPDATE review_question_answers SET
> answer=:answer WHERE review_question_answers.id =
> :review_question_answers_id
> [2006-07-24 17:06:06,243] [engine]: {'answer': '',
> 'review_question_answers_id': 250}
> [2006-07-24 17:06:06,243] [engine]: UPDATE review_question_answers SET
> answer=:answer WHERE review_question_answers.id =
> :review_question_answers_id
> [2006-07-24 17:06:06,243] [engine]: {'answer': '',
> 'review_question_answers_id': 251}
> [2006-07-24 17:06:06,253] [engine]: SELECT
> review_question_answers_seq.nextval FROM DUAL
> [2006-07-24 17:06:06,253] [engine]: None
> [2006-07-24 17:06:06,253] [engine]: INSERT INTO
> review_question_answers (id, review_id, question_id, answer) VALUES
> (:id, :review_id, :question_id, :answer)
> [2006-07-24 17:06:06,253] [engine]: {'answer': None, 'id': 299,
> 'review_id': None, 'question_id': None}
> [2006-07-24 17:06:06,253] [engine]: ROLLBACK
> **** review.update, exception: (DatabaseError) ORA-01400: cannot
> insert NULL into ("QACLAIMS"."REVIEW_QUESTION_ANSWERS"."REVIEW_ID")
>  'INSERT INTO review_question_answers (id, review_id, question_id,
> answer) VALUES (:id, :review_id, :question_id, :answer)' {'answer':
> None, 'id': 299, 'review_id': None, 'question_id': None}
>
> has anyone experienced something like this?
>
> ---------------------------------------------------------------------- 
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to  
> share your
> opinions on IT & business topics through brief surveys -- and earn  
> cash
> http://www.techsay.com/default.php? 
> page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to