I'm getting errors inside beancount/ops/summarize.py while using
beanquery's run_query() programmatically.  This is on a beancount ledger
that works fine when I run bean-query from the command line.  I'm not sure
if I'm failing to use the programmatic API correctly or if there's
something else going on.

bean-query access (works):

subprocess.run(["bean-query", ledger, query], check=True,
capture_output=True)

Programmatic access (doesn't work):

entries, errors, options = parser.parse_file(ledger)
run_query(entries, options, query)

The first error I got was this:
  ....
  File "/home/eric/crypto-taxes/beancount/beancount/ops/summarize.py", line
497, in conversions
    narration = 'Conversion for {}'.format(conversion_balance)
  File "/home/eric/crypto-taxes/beancount/beancount/core/inventory.py",
line 122, in __str__
    return self.to_string()
  File "/home/eric/crypto-taxes/beancount/beancount/core/inventory.py",
line 114, in to_string
    ', '.join(pos.to_string(dformat) for pos in sorted(self)))
  File "/home/eric/crypto-taxes/beancount/beancount/core/position.py", line
246, in __lt__
    return self.sortkey() < other.sortkey()
  File "/home/eric/crypto-taxes/beancount/beancount/core/position.py", line
227, in sortkey
    if self.cost.number:
AttributeError: 'CostSpec' object has no attribute 'number'

This was only a little surprising because I'm using the "{USD}" cost-spec
hack, and I've had to elsewhere tweak beancount-core to be robust to such
cost specs.  It's still a bit surprising since as I said don't get this
error when running the bean-query tool on the same file.  Anyway, I hacked
the comparator and got past this point, to:
  ....
  File "/home/eric/crypto-taxes/beancount/beancount/ops/summarize.py", line
480, in conversions
    conversion_balance = interpolate.compute_entries_balance(entries,
date=date)
  File "/home/eric/crypto-taxes/beancount/beancount/core/interpolate.py",
line 275, in compute_entries_balance
    total_balance.add_position(posting)
  File "/home/eric/crypto-taxes/beancount/beancount/core/inventory.py",
line 461, in add_position
    return self.add_amount(position.units, position.cost)
  File "/home/eric/crypto-taxes/beancount/beancount/core/inventory.py",
line 416, in add_amount
    key = (units.currency, cost)
AttributeError: type object 'MISSING' has no attribute 'currency'

So somehow I've got a missing value for some units.  I started tweaking
this code too to be robust to this case, but there were too many places
where it's assumed not-missing, and it seemed sketch to be hacking the code
for adding to inventories this way.

Any idea what's going on?

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/CAFXPr0st_mX_NyovM%2BDkr8XJ%3D7Q048kOa8JHhUfCyaAcP9M0Zw%40mail.gmail.com.

Reply via email to