Dependency between "Session/line number was not unique in database." error and Python code

It is only a partial answer - the bounty is still eligible.

The error does depend on my code - at least when there is SyntaxError.

I have reproduced it with three following cells.

In [31]: print(1)
         1

In [31]: print 2
           File "<ipython-input-32-9d8034018fb9>", line 1
             print 2
                   ^
         SyntaxError: Missing parentheses in call to 'print'

In [32]: print(2)
         2
         ERROR! Session/line number was not unique in database. History logging moved to new session 7

As you can see the line counter has been not increased in the second cell (with syntax issues).

Inspired by @zwer's comment, I have queried the $HOME/.ipython/profile_default/history.sqlite database:

sqlite> select session, line, source from history where line > 30;
6|31|print(1)
6|32|print 2
7|32|print(2)

It is clear that the line counter for the second cell has been increased in the database, but not in the notebook.

Thus when the third cell has been executed successfully, the notebook attempted to store its source with the same line, which offended the PRIMARY KEY constraint:

sqlite> .schema history
CREATE TABLE history
                (session integer, line integer, source text, source_raw text,
                PRIMARY KEY (session, line));

As a result, a failsafe has been triggered which issued the warning and created a new session.

I guess the issue is not affecting my code behaviour, however I miss a credible source for such statement.