Why is lineno required when creating Transactions in an importer?

53 views
Skip to first unread message

Oon-Ee Ng

unread,
May 8, 2021, 9:40:30 AM5/8/21
to bean...@googlegroups.com
So creating a new Transaction looks something like the below:-

            meta = data.new_metadata(file.name, lineno)
            txn = data.Transaction(
                meta, date, self.FLAG, None, description,
                data.EMPTY_SET, data.EMPTY_SET, [
                    data.Posting(account_name, amount_val, None, None, None, None),
                    data.Posting(account_name_2, -amount_val, None, None, None, None)
                ]
            )

If I don't specify metadata at all (use an empty dictionary) then it will throw a KeyError from line 586 in core/data.py in entry_sortkey

But if I just specify a nonsense value (identical across all transactions) it works, and doesn't affect anything else.

Does it make more sense not to require metadata at all when creating Transactions?

James Cook

unread,
May 8, 2021, 10:08:22 AM5/8/21
to bean...@googlegroups.com
I've run into a similar issue when my plugins emit errors. If I leave
the source field of the error empty (None or {}), then beancount raises
an exception somewhere (I could check if it's useful).

Normally I can just copy the meta attribute od the entry that caused
the error, but some of my errors don't correspond to a particular entry
--- e.g. end-of-day checks, or syntax errors in the configuration. In
those cases, I set source to {"filename": None, "lineno": None} just to
appease beancount, but it feels silly.

--
James

Martin Blais

unread,
May 8, 2021, 11:13:07 AM5/8/21
to Beancount
Just a consequence of using namedtuples.
The next version won't require it


--
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/CAGQ70etbHO%2BAoBHK9-A5tehOATGozm6A7xn2wYb7KOLhgzswuQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages