After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 634165 - Better dealing with a locked database (for example after crash of gnucash)
Better dealing with a locked database (for example after crash of gnucash)
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Python Bindings
git-master
Other Linux
: Normal enhancement
: ---
Assigned To: Mark Jenkins
Mark Jenkins
Depends on:
Blocks:
 
 
Reported: 2010-11-06 14:40 UTC by Christoph Holtermann
Modified: 2018-06-29 22:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
(I)Pythons output when trying to access a locked database (1.67 KB, application/octet-stream)
2010-11-06 14:40 UTC, Christoph Holtermann
  Details
This patch extends the function Session.__init__() with ignore_lock (1.17 KB, patch)
2010-11-09 10:59 UTC, Christoph Holtermann
committed Details | Review
Add clean-local: rule to Makefile.am to remove gnucash_core.c (424 bytes, patch)
2010-11-11 16:19 UTC, Mike Evans
committed Details | Review
add "force_new=False" to Session._init_ (1.40 KB, patch)
2010-11-12 15:16 UTC, Mike Evans
committed Details | Review

Description Christoph Holtermann 2010-11-06 14:40:08 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.
Comment 1 Christoph Holtermann 2010-11-09 10:56:52 UTC
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.
Comment 2 Christoph Holtermann 2010-11-09 10:59:03 UTC
Created attachment 174125 [details] [review]
This patch extends the function Session.__init__() with ignore_lock
Comment 3 Mike Evans 2010-11-11 12:23:22 UTC
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
Comment 4 Mike Evans 2010-11-11 12:55:31 UTC
Apologies to John, not his fault at all.  Make clean doesn't remove/rebuild src/optional/python-bindings/gnucash_core.c.
Comment 5 Christoph Holtermann 2010-11-11 13:50:19 UTC
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
Comment 6 Mike Evans 2010-11-11 16:19:14 UTC
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 7 Christian Stimming 2010-11-12 08:00:32 UTC
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.
Comment 8 Christoph Holtermann 2010-11-12 10:42:33 UTC
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.
Comment 9 Mike Evans 2010-11-12 15:16:51 UTC
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.
Comment 10 John Ralls 2010-11-12 16:57:53 UTC
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)?
Comment 11 Mike Evans 2010-11-12 17:10:40 UTC
(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.
Comment 12 Christoph Holtermann 2010-11-12 22:48:24 UTC
(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 13 Christian Stimming 2010-11-14 13:26:39 UTC
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!)
Comment 14 Christian Stimming 2010-11-14 13:28:00 UTC
This bug is closed now, isn't it?
Comment 15 Mike Evans 2010-11-14 14:59:44 UTC
It appears to resolved to me.
Comment 16 John Ralls 2010-11-14 17:08:43 UTC
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.
Comment 17 Christoph Holtermann 2010-11-14 18:43:33 UTC
Sure, just go ahead ! I would have tried if no one else did. Thanks for the attention.
Comment 18 John Ralls 2010-11-15 19:19:30 UTC
Done, in r19812.
Comment 19 John Ralls 2010-11-15 19:20:19 UTC
Comment on attachment 174262 [details] [review]
Add clean-local: rule to Makefile.am to remove gnucash_core.c

In modified form.
Comment 20 John Ralls 2018-06-29 22:46:41 UTC
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.