Why is there a duplicate `include` error?

36 views
Skip to first unread message

Aaron Stacy

unread,
Mar 2, 2026, 7:32:47 PM (4 days ago) Mar 2
to bean...@googlegroups.com
The beancount loader has an error if a file is imported multiple times (code). 

I noticed because I was trying to organize my ledger something like this:

ledger_deps.png

And got the error. I want each of banking.beancount and income.beancount to include accounts.beancount because my editor plugin will give me errors if I don't (since the accounts aren't defined).

Looks like this functionality has been around just about as long as the include directive (commit), and I couldn't find any docs on why this would be an error.

When I remove the error, the loading logic seems to work fine. Any chance I could mail a PR to remove this error?

Timothy Jesionowski

unread,
Mar 2, 2026, 7:55:05 PM (4 days ago) Mar 2
to bean...@googlegroups.com
I would love for that restriction to be removed. Never thought about patching it myself, I hope there's no deep architectural reason for that constraint?



Sincerely,
Timothy Jesionowski

--
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 visit https://groups.google.com/d/msgid/beancount/CACjABknxqNpEK0EgQK7PVh76sUkO41hF%2B6QxSTR91D6U9Z4kag%40mail.gmail.com.

Simon Guest

unread,
Mar 2, 2026, 8:16:02 PM (4 days ago) Mar 2
to bean...@googlegroups.com
I had a quick look at this in limabean, and it's easily done for sure.

But there seems to be one hard problem:  the tag and metadata context prior to inclusion in each place may differ.  In my quick implementation, only the first is honoured.  Which is a bit of a dirty hack, eh?


pushtag #included
include "include-duplicate/included.beancount"
poptag #included

pushtag #duplicate-include
include "include-duplicate/included.beancount"
poptag #duplicate-include


results in:

2023-05-31 * "Include some beer" #included
  Assets:Bank:Current -15.30 NZD
  Expenses:Entertainment:Drinks-and-snacks

2023-06-01 * "Inclusion is everything" #included
  Assets:Bank:Current -5.65 NZD
  Expenses:Groceries


Oops, missing that #duplicate-include tag.  🤷

Simon Guest

unread,
Mar 2, 2026, 11:42:28 PM (4 days ago) Mar 2
to bean...@googlegroups.com
It turned out not to be too difficult to do what I believe is the right thing, in limabean at least.

The right thing in my view is to allow the duplicate include if and only if the include context of tags and metadata is identical.

This is now implemented on main branch of limabean, although not yet in an official release.  (I have some work to finish on plugins before making a new release.)


And for example:

kiri> limabean --beanfile examples/beancount/multiple-includes.beancount
[Rebel readline] Type :repl/help for online help info
[limabean] 5 directives loaded from examples/beancount/multiple-includes.beancount

user=> (show (journal))
2014-01-27  Income:Donations    Donations  -100.00  NZD  -100.00 NZD
2014-01-27  Assets:Common       Donations   100.00  NZD
2014-02-05  Income:Work         Work       -750.00  NZD  -750.00 NZD
2014-02-05  Assets:Common       Work        750.00  NZD
:ok


kiri> limabean --beanfile examples/beancount/multiple-includes-different-context.beancount
[Rebel readline] Type :repl/help for online help info
Error: duplicate include
   ╭─[ examples/beancount/multiple-includes/included-2.beancount:1:9 ]
   │
 1 │ include "common.beancount"
   │         ─────────┬────────
   │                  ╰────────── context #include-2
   │
   ├─[ examples/beancount/multiple-includes/included-1.beancount:1:9 ]
   │
 1 │ include "common.beancount"
   │         ─────────┬────────
   │                  ╰────────── context #include-1
───╯


This was pretty easy to implement in limabean's Rust parser as the codebase is still quite fresh, and, well, Rust.

Hoping that someone will be able to enjoy this.  And that someone else might be able to add a similar implementation for OG Beancount. 🤞

David Avraamides

unread,
Mar 3, 2026, 6:31:21 AM (4 days ago) Mar 3
to bean...@googlegroups.com
Couldn't you just include accounts.beancount in main.beancount before banking.beancount and income.beancount? That's what I do. My main.bean (simplified) is:

; global stuff
include "commodities.bean"
include "accounts.bean"
include "prices.bean"

; individual account history
include "data/amazon_david.bean"
include "data/amazon_karen.bean"
include "data/amex_david.bean"
include "data/amex_karen.bean"
(many more individual account includes...)
...

And then I don't have any other include statements in the account-specific bean files.

Or does that not address your problem?

--

Timothy Jesionowski

unread,
Mar 3, 2026, 9:54:37 AM (4 days ago) Mar 3
to bean...@googlegroups.com
It constrains the file architecture, and in particular means you have to carefully duplicate a lot of include directives to have different main.beancount files tracking the same (or mostly the same) ledger.



Sincerely,
Timothy Jesionowski

Aaron Stacy

unread,
Mar 4, 2026, 8:13:09 AM (3 days ago) Mar 4
to Beancount
On Tuesday, March 3, 2026 at 5:31:21 AM UTC-6 David Avraamides wrote:
Couldn't you just include accounts.beancount in main.beancount before banking.beancount and income.beancount? That's what I do. My main.bean (simplified) is:

; global stuff
include "commodities.bean"
include "accounts.bean"
include "prices.bean"

; individual account history
include "data/amazon_david.bean"
include "data/amazon_karen.bean"
include "data/amex_david.bean"
include "data/amex_karen.bean"
(many more individual account includes...)
...

And then I don't have any other include statements in the account-specific bean files.

Or does that not address your problem?

Checking the main ledger would work, but unfortunately editor plugins would highlight errors in the individual account histories. I find these inline errors a nice time saver when reconciling imports.
Reply all
Reply to author
Forward
0 new messages