ledger / ledger

Double-entry accounting system with a command-line reporting interface
https://www.ledger-cli.org
Other
5.3k stars 501 forks source link

Opening 2 journals leads to RuntimeError: Assertion failed in "src/session.cc", line 185: std::size_t ledger::session_t::read_data(const string&): xact_count == journal->xacts.size() (BZ#973) #973

Closed tbm closed 9 months ago

tbm commented 11 years ago

Note: the issue was created automatically with bugzilla2github

Bugzilla bug ID: BZ#973 From: Martin Michlmayr (@tbm) CC: unknown user, @egh, unknown user, @afh

tbm commented 9 years ago

Comment author: unknown user

FWIW I see the same error when trying to open the same file two times in a row, even if I insert a "ledger.session.close_journal_files()" between the calls.

tbm commented 10 years ago

Comment author: Wilfred Hughes

Note that this bug also occurs when following the tutorial. It's mentioned on the mailing list: https://groups.google.com/forum/#!msg/ledger-cli/CRmG59U0GbY/VTwz030bGIcJ

I can reproduce by downloading the example file drewr3.dat and running the following command from the tutorial:

$ ledger -f drewr3.dat cleared
     $ -3,804.00          $ 1,000.00                 Assets
      $ 1,396.00          $ 1,000.00    03-Dec-01      Checking
         $ 30.00                   0                     Business
     $ -5,200.00                   0                   Savings
     $ -1,000.00         $ -1,000.00    03-Dec-01    Equity:Opening Balances
      $ 6,654.00                   0                 Expenses
      $ 5,500.00                   0                   Auto
         $ 20.00                   0                   Books
        $ 300.00                   0                   Escrow
        $ 334.00                   0                   Food:Groceries
        $ 500.00                   0                   Interest:Mortgage
     $ -2,030.00                   0                 Income
     $ -2,000.00                   0                   Salary
        $ -30.00                   0                   Sales
        $ -63.60                   0                 Liabilities
        $ -20.00                   0                   MasterCard
        $ 200.00                   0                   Mortgage:Principal
While evaluating value expression:
  (latest_cleared ? (format_date(latest_cleared) : "         "))
Error: Assertion failed in "/home/wilfred/aur/ledger/src/ledger-3.0.1/src/post.cc", line 109: virtual ledger::date_t ledger::post_t::primary_date() const: xact
tbm commented 10 years ago

Comment author: Alexis (@afh)

I've been at this for quite a while and am still uncertain how to fix this best. In the following I describe my understanding of the bug:

session.read_data() asserts that the number of transactions read from the current file is the same as the number of the transactions in the current journal object it holds.

This journal objects "remembers" all transactions that have been read.

Clearing all transactions on that journal object (using xacts.clear(), see attached patch) "fixes" the bug.

Yet I think a proper solution should work on a different level.

For example there is a set_flush_on_next_data_file() method on the session object, with which the data_files on the session can be cleared.

I do hope that this brief description will trigger some ideas for someone with a better architectural understanding of ledger than me.

In the meantime I'll keep reading and learning the code.

tbm commented 10 years ago

Comment author: Alexis (@afh)

Created attachment 99 Patch that clears the xacts from the journal upon every read

Attached file: 973_journal.cc.patch (text/plain, 353 bytes) Description: Patch that clears the xacts from the journal upon every read

tbm commented 10 years ago

Comment author: Erik Hetzner (@egh)

I've seen this too.

tbm commented 10 years ago

Comment author: Erik Hetzner (@egh)

Bug BZ#972 has been marked as a duplicate of this bug.

tbm commented 10 years ago

Comment author: Erik Hetzner (@egh)

Bug BZ#974 has been marked as a duplicate of this bug.

tbm commented 11 years ago

Comment author: Martin Michlmayr (@tbm)

I get the following runtime error when I try to open two journal files:

Traceback (most recent call last):
  File "t9.py", line 6, in <module>
    journal2 = ledger.read_journal("2013")
RuntimeError: Assertion failed in "/home/tbm/ledger/src/session.cc", line 185: std::size_t ledger::session_t::read_data(const string&): xact_count == journal->xacts.size()
terminate called after throwing an instance of 'int'
Aborted

Python file to reproduce:

import ledger

journal1 = ledger.read_journal("2012")
# do something with 2012 journal...

journal2 = ledger.read_journal("2013")
# do something with 2013 journal...

I found ledger.session.close_journal_files() and tried to put that between the two read_journal() calls but that leads to a different error.

afh commented 9 months ago

Closing as duplicate of #514