Python bindings, Transactions, warnings and crashes

Christoph Holtermann c.holtermann at gmx.de
Fri Sep 3 13:08:24 EDT 2010


 Hello !

These days I have worked a bit with python-bindings to create transactions.
Actually after the CSV-Import crashed for my banks data, I decided to try
that myself as a python script and it all worked fine.
It is a bit weird though, to find the right order of calling the funtions as it
has been described in recent mails but with BeginEdit() and CommitEdit()
everything works fine.
I tried for some hour to find out, why my description did not show up in the
transaction only to find that my strings contained badly coded Umlauts
("Ü","ä",...) which made me finally understand how codecs in python work ;-)
The gnucash engine didn´t show me an error when I put them. They just
didn´t show up in the gui. I´m not sure if I tried to reread them after writing,
but I think I did successfully.

Thanks for the work on the bindings ! That´s really what I have been looking
for for quite a while. Actually I´m still angry with myself that I told my father ten
years ago to use Quicken and to get rid of his DBase-scripts that he wrote
himself. It´s so nice to be able to WORK with your data !

best regards,

Christoph Holtermann


Am 02.08.2010 21:12, schrieb Mark Jenkins:
> Daniele Varrazzo :
>> I have an issue with the transactions creation: if I add splits to the
>> transaction before setting the currency I get a few warnings:
>>
>>   * 18:04:09  CRIT <gnc.engine> [xaccTransScrubSplits()] Transaction
>> doesn't have a currency!
>>   * 18:04:09  CRIT <gnc.engine.scrub>
>> [xaccScrubUtilityGetOrMakeAccount()] No currency specified!
>>   * 18:04:09  CRIT <gnc.engine.scrub> [get_balance_split()] Can't get
>> balancing account
>>
>> and an empty "imbalance-CCY" account is created. OTOH, if i set the
>> currency (or the description) on the transaction, the process
>> segfaults
>>
>>   * 18:10:07  WARN <GLib-GObject> instance of invalid
>> non-instantiatable type `<invalid>'
>>   Segmentation fault
>>
>> I suspect the problem is known as the scripts in the examples
>> directory are careful in setting the transaction details after the
>> first split - I can live whit that once I know the problem.
> This is a nice co-incidence. I was dealing with the same thing today.
>
> What I used to do was not call any Transaction set functions until the
> splits had been assigned; which would only result in critical warnings
> and not segfaults.
>
> Today I discovered how to avoid the warnings and crashes entirely
> without such a forced order; one should use Transaction.BeginEdit() and
> Transaction.CommitEdit() and do everything in between.
>
> I'm going to update all of the
> src/optional/python-bindings/example_scripts to do things that way in an
> upcoming patch submission.
>
>> Is there a way to avoid the creation of the imbalance accounts too?
> There is Transaction.GetImbalance() and Transaction.GetImbalanceValue().
>  These are actually what I was working with today and in order to test
> them out with the Trading Account feature enabled I discovered that I
> had to use Transaction.BeginEdit() and Transaction.CommitEdit() or else
> I ended up with the problem of transactions being created to balance my
> transaction out, and GetImbalance() not showing an imbalance at all.
>
> So, if you apply the patch I just (re-)submitted, and first use
> Transaction.BeginEdit() (see the example in the patch I submitted), you
> can check to see if your transaction is imbalanced using
> Transaction.GetImbalance() before finalizing with Transaction.CommitEdit().
>
>> In the next days I may have more questions about the python bindings,
>> and hopefully some patches to provide back. Is this the best ML to
>> talk about the argument or there is something more specific?
> I'd say it is. Ultimately, questions about the python bindings come down
> to either:
>  * how the GnuCash C api (which the python bindings wrap) should be
> used. (best answered by developers)
>  * requests for python binding enhancements/fixes. (which only
> developers can pull off)
>
> As one of the original python bindings contributors, and as someone who
> has some funding right now to maximize their chances of making it into
> 2.4, I personally try to keep an eye out on both gnucash-devel and
> gnucash-user for python binding questions. I have specific filters that
> look for traffic to those lists with python in the subject line, which
> helps me pick them up out from all the other list traffic.
>
> Let me know if my patch for GetImbalance(), GetImbalanceValue(), and the
> new example script help.
>
>
> Mark Jenkins
> Member ParIT Worker Co-op
>
> cc Scott
> cc fellow members
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel



More information about the gnucash-devel mailing list