GNOME Bugzilla – Bug 634165
Better dealing with a locked database (for example after crash of gnucash)
Last modified: 2018-06-29 22:46:41 UTC
Created attachment 173948 [details] (I)Pythons output when trying to access a locked database When the (in my case MySql)-database is locked for example after a crash of gnucash and afterwards an access via the python-bindings is tried, there will be a quite unintuitive error message ( output attached ) because the lock of the database has not correctly been removed. It would be good, if the error message would mention the lock as the reason for not being able to open the session. A workaround to access the database is to remove the lock, for example in the shell with echo "TRUNCATE GNCLOCK;" | mysql gnucash It would be good if this call could be implemented into the python-bindings for not to open a second communication channel to the database.
For the second enhancement proposal i have attached a simple patch which adds the argument ignore_lock to Session.__init__() which is passed through to qof_session_begin.
Created attachment 174125 [details] [review] This patch extends the function Session.__init__() with ignore_lock
Applying this patch, via git svn fetch & merge give me compile error. gnucash_core.c: In function '_wrap_qof_session_begin': gnucash_core.c:14238: error: too few arguments to function 'qof_session_begin' However, further investigation reveals that John Rails' bug 634392 has added "force" to session_begin(parameter to and so breaks the python bindings. System: Fedora12
Apologies to John, not his fault at all. Make clean doesn't remove/rebuild src/optional/python-bindings/gnucash_core.c.
In one try directly after reading your message I also got a broken build, when I only compiled the python-bindings directory. It seems to me that the function qof_session_begin has gotten an additional argument and that this has to be reflected in the file gnucash_core.c which is created by SWIG. In my actual build which works and which I have done from the root of the source, the file gnucash_core.c has changed and added an fifth argument. I don´t yet understand how SWIG works but it seems that it isn´t enough to make clean in the current directory. Another step that I took was that i manually deleted gnucash_core.c. I can´t reproduce the error anymore. I just now tried to see how the files in libqof/qof changed by svn diff -r 19769 (which is the revision before my patch came into play) but I get network errors at the moment like having been reported on the developer list in the recent past. svn: OPTIONS von »http://svn.gnucash.org/repo/gnucash/trunk/src/libqof/qof«: Konnte keine Verbindung zum Server herstellen (http://svn.gnucash.org). So it seems to me that the errors are not in relation to my change but to the building process in relation to the mentioned change in /src/libqof/qof/qofsession.h
Created attachment 174262 [details] [review] Add clean-local: rule to Makefile.am to remove gnucash_core.c Not sure if this should be a separate bug but... Since make clean doesn't remove gnucash_core.c I've added a rule to do so.
Comment on attachment 174262 [details] [review] Add clean-local: rule to Makefile.am to remove gnucash_core.c No, I think the solution is differently: The problem is that the generated gnucash_core.c does not (yet) have a makefile dependency on all of its include files. For the *.o files the autotools generate those dependencies themselves, but for this .c file we do not have that dependency but only those dependencies which are explicitly written in Makefile.am line 47. Most of the times, the dependency on config.h is sufficient to have it generated anew. By coincidence, John's change did not touch config.h but only some other headers included by gnucash_core.c so that this rule didn't trigger. The solution is to add all or at least almost all of gnucash_core.c's include files in Makefile.am line 47 as explicit dependencies.
I just opened <a href="https://bugzilla.gnome.org/show_bug.cgi?id=634673"> Bug 634673 </a> to cover the topic of the makefile for that is something different than the original bug which focuses on the locked database while the compile thing is something more general.
Created attachment 174329 [details] [review] add "force_new=False" to Session._init_ add another parameter to gnucash_core.py to match new parameter in qof_session_begin(). See Bug 634392 for more details.
Mightn't it be better to have the order of GnucashCoreClass.begin()'s arguments match qof_session_begin? (book_url, ignore_lock, is_new, force_new rather than book_url, is_new, ignore_lock, force_new)?
(In reply to comment #10) > Mightn't it be better to have the order of GnucashCoreClass.begin()'s > arguments match qof_session_begin? (book_url, ignore_lock, is_new, force_new > rather than book_url, is_new, ignore_lock, force_new)? I'm not sure why the original order was as it is, so I just appended force_new. I also considered that changing the order would likely break existing python scripts, so I took the safest option. Otherwise I agree, they should be in the same order.
(In reply to comment #11) > (In reply to comment #10) > > Mightn't it be better to have the order of GnucashCoreClass.begin()'s > > arguments match qof_session_begin? (book_url, ignore_lock, is_new, force_new > > rather than book_url, is_new, ignore_lock, force_new)? > > I'm not sure why the original order was as it is, so I just appended force_new. > I also considered that changing the order would likely break existing python > scripts, so I took the safest option. Otherwise I agree, they should be in the > same order. I had the same thought, that it would be better to have the same order of arguments - a bit after having suggested the additional option. It didn´t seem to offending to me for it seemed save to add a last argument. But then Bug 634673 came and took my time. I still intend to sort the options and check if there is a breaking of any scripts. It may take a week or not for i should do some studying for my final medical exam ;-)
Comment on attachment 174329 [details] [review] add "force_new=False" to Session._init_ r19801, thanks a lot. (@jralls: Please remember to set the attachment status to "Committed", under attachments -> "Details". Thanks!)
This bug is closed now, isn't it?
It appears to resolved to me.
I'm waiting for Christoph to tell us whether we can reorder the arguments in Session.__init__() to match qof_session_begin(). OTOH, maybe I should just do it. I think it will prevent much future confusion.
Sure, just go ahead ! I would have tried if no one else did. Thanks for the attention.
Done, in r19812.
Comment on attachment 174262 [details] [review] Add clean-local: rule to Makefile.am to remove gnucash_core.c In modified form.
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=634165. Please update any external references or bookmarks.