Order of padding and plugins

89 views
Skip to first unread message

Soham Shanbhag

unread,
Dec 4, 2023, 3:12:13 PM12/4/23
to Beancount
Hi,
I've been using padding to account for errors in my accounts and bank, for example for transactions which I may have forgotten but are small enough that I don't want to hunt for them. Usually, this goes along the lines of:

2023-12-04 pad Assets:Checking Equity:Adjustments
2023-12-05 balance Assets:Checking 1000 USD

whenever I want to check an account in beancount with my bank. I'm also using plugins which manipulate the transactions. However, beancount loads the padding plugin (ops.pad) before my custom plugins in PLUGINS_PRE(see beancount/loader.py), which leads to padding the accounts with values before manipulation by my plugin. Since the balance directive is in PLUGINS_POST, this leads to an error. For an example, see the following beancount file and plugin file:

; file: temp.beancount
option "operating_currency" "USD"
option "insert_pythonpath" "True"
plugin "plugin_temp"

2020-01-01 open Equity:Adjustments
2020-01-01 open Assets:Checking          USD
2020-01-01 open Expenses:Groceries

2023-01-01 pad Assets:Checking Equity:Adjustments
2023-01-02 balance Assets:Checking 1000 USD

2023-02-01 * "Eggs"
    Expenses:Groceries          100 USD
    Assets:Checking

2023-03-01 pad Assets:Checking Equity:Adjustments
2023-03-02 balance Assets:Checking 700 USD

; file: plugin_temp.py in the same directory

from beancount.core import data

__plugins__ = ('plugin_temp',)

def plugin_temp(entries, unused_options_map):
    new_entries = list(e for e in data.filter_txns(entries) if e.flag == '*')
    return new_entries + entries, []


With bean-check, this gives the error
Balance failed for 'Assets:Checking': expected 700 USD != accumulated 600 USD (100 too little)

   2023-03-02 balance Assets:Checking                                 700 USD

Is there a particular reason ops.pad is in PLUGINS_PRE and not in PLUGINS_POST? Putting ops.pad in PLUGINS_POST seems to solve this issue.


Also, it seems that issue https://groups.google.com/g/beancount/c/bMo9A6lM9Z4/m/egj3rGBMBAAJ is still unsolved. This also affects my above workflow, but I'm presently easily sidestepping it by not using padding on an account where I do balance checks.

Soham Shanbhag

unread,
Dec 11, 2023, 7:01:01 AM12/11/23
to Beancount
I see that there is an open issue on github related to this too, see https://github.com/beancount/beancount/issues/742.

The present behaviour does not satisfy the definition of the pad directive in the language syntax, i.e. it does not 'insert a transaction that will make the subsequent balance assertion succeed, if it is needed'. To ensure this, in my opinion, ops.pad needs to be in PLUGINS_POST. I'm willing to file a PR on github(it's a two line change) but wanted to confirm that this doesn't break any other functionality.

Martin Blais

unread,
Dec 11, 2023, 8:12:32 AM12/11/23
to Beancount
Thank you for reporting it Soham.



--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/02d0ae5f-599a-4c4b-94d9-a3f58ead8615n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages