Project

General

Profile

Crash on Session::find() after a Session.add() with constraint failed error

Added by Rodolphe Basset about 10 years ago

Hello,

I made successfull code to load related objects in sqlite3 db from CSV files, using Session::add() and related Transaction object.

I test my inserts with successfull Session::find()

When I start from empty database, all is OK.

When I run with existing database, Session::add() should lead Transaction destructor to throw an Exception and rollback().

Exception is thrown, with message :

"Sqlite3: insert into "line" ("version", "name", "type", "annual_goal") values (?, ?, ?): constraint failed ()"

but all subsequent calls to Session::find() in another Transaction crashes (segmentation fault) in

Session::flush(), far before SqlStatement is even constructed !? And why need to flush() ?

Here's the stack before the crash...

somewhere in ~basic_string() (basic_string.h:538)

12 _fu204___ZNSs4_Rep20_S_empty_rep_storageE() Sqlite3.C:32 0x004a9d6b  
11 Wt::Dbo::backend::Sqlite3Statement::handleErr() Sqlite3.C:473 0x004acf14 
10 Wt::Dbo::backend::Sqlite3Statement::execute() Sqlite3.C:216 0x004abaf7   
9 Wt::Dbo::SaveBaseAction::exec() DbAction.C:150 0x004713c3 
8 Wt::Dbo::SaveDbAction<safety::Line>::visit() DbAction_impl.h:498 0x004847c6   
7 Wt::Dbo::Session::implSave<safety::Line>() Session_impl.h:282 0x004a6f7e  
6 Wt::Dbo::MetaDbo<safety::Line>::flush() ptr_impl.h:80 0x00497e43  
5 Wt::Dbo::Session::flush() Session.C:1082 0x0046fc2c   
4 Wt::Dbo::Query<Wt::Dbo::ptr<safety::Line>, Wt::Dbo::DynamicBinding>::resultList() Query_impl.h:483 0x004d12b4 
3 Wt::Dbo::Query<Wt::Dbo::ptr<safety::Line>, Wt::Dbo::DynamicBinding>::operator Wt::Dbo::collection<Wt::Dbo::ptr<safety::Line> >() Query_impl.h:505 0x004d1715  
2 exportLineCSV() main.cpp:282 0x00404118   
1 _fu32___ZSt4cout() main.cpp:328 0x0040477b

the sqlite err was 19 (SQLITE_CONSTRAINT)

I tried to discard dirty objects and rereadAll :

session.discardUnflushed();

with no success...

Something is messed up somewhere, but I can't see...

Any help ?

(Running on Windows XP / Eclipse 4.3 CDT / MinGW, using WT 3.3.1 or Wt 3.3.2 RC2 with no change...)


Replies (7)

RE: Crash on Session::find() after a Session.add() with constraint failed error - Added by Koen Deforche about 10 years ago

Hey,

The constraint failed is a valid error, I suppose?

This has as consequence that some objects are not being saved. You can do 'rereadAll()' which will discard any changes (discuardUnflushed() only works for manual flushing, ASFAIK).

The flush() happens before doing a query because there may be unsaved changes that first are flushed to the database, as they may affect the outcome of a query.

Regards,

koen

RE: Crash on Session::find() after a Session.add() with constraint failed error - Added by Rodolphe Basset about 10 years ago

Koen Deforche wrote:

Hey,

The constraint failed is a valid error, I suppose?

>

indeed !

This has as consequence that some objects are not being saved. You can do 'rereadAll()' which will discard any changes (discuardUnflushed() only works for manual flushing, ASFAIK).

>

THIS is the clue I needed !

I'm in AutoMode

I'll have a look at that, thanks !

RE: Crash on Session::find() after a Session.add() with constraint failed error - Added by Rodolphe Basset about 10 years ago

:-(

Does not work.

Session always crash on the first subsequent find(), event if I .rereadAll()

Always throws the first dbo::Exception.

Seems like this session is "broken", and no way to reset it.

Do I need to dynamically instantiate it as a

Session * ptrSession = new Session();

in order to start with a new session ?

RE: Crash on Session::find() after a Session.add() with constraint failed error - Added by Koen Deforche about 10 years ago

That sounds like a bug then.

Perhaps a rereadAll() does not remove the newly added pointer from the session. Does it get fixed when you do ptr.remove() on the offending object?

Regards,

koen

RE: Crash on Session::find() after a Session.add() with constraint failed error - Added by Rodolphe Basset about 10 years ago

That sounds like a bug then.

Perhaps a rereadAll() does not remove the newly added pointer from the session. Does it get fixed when you do ptr.remove() on the offending object?

>

There are Session::dirtyObjects_.node_count > 0 in the session when flush() crashes.

Before flush, there are 20 ones, after Exception is thrown, there are 19 left !

But how can I access these objects to perform the ptr.remove() you suggest ?

They are protected members.

thanks for helping

RE: Crash on Session::find() after a Session.add() with constraint failed error - Added by Koen Deforche about 10 years ago

Hey,

I think we need to treat this as a bug; rereadAll() should also evict newly added ptr's from the session. It was merely a question to see if you could confirm that this is indeed the resolution needed. The offending object is the one with the constraint failure problem, perhaps you have a pointer to it in your application?

Can you file a bug for this?

Regards,

koen

    (1-7/7)