home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

32 rows where "created_at" is on date 2023-05-08 and user = 9599 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: issue_url, reactions, created_at (date), updated_at (date)

issue 15

  • `table.upsert_all` fails to write rows when `not_null` is present 8
  • upsert of new row with check constraints fails 5
  • `Table.convert()` skips falsey values 3
  • Repeated calls to `Table.convert()` fail 2
  • add ability to configure "on delete" and "on update" attributes of foreign keys: 2
  • Show more information when JSON can't be imported with sqlite-utils insert 2
  • Support self-referencing FKs in `Table.create` 2
  • Reading rows from a file => AttributeError: '_io.StringIO' object has no attribute 'readinto' 1
  • upsert new rows with constraints, fixes #514 1
  • Fixes breaking DEFAULT values 1
  • rows_from_file() raises confusing error if file-like object is not in binary mode 1
  • Enable `Table.convert()` on falsey values 1
  • ResourceWarning: unclosed file 1
  • Get tests to pass with `pytest -Werror` 1
  • Remove `skip_false=True` and `--no-skip-false` in `sqlite-utils` 4.0 1

user 1

  • simonw · 32 ✖

author_association 1

  • OWNER 32
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions issue performed_via_github_app
1539157643 https://github.com/simonw/sqlite-utils/pull/537#issuecomment-1539157643 https://api.github.com/repos/simonw/sqlite-utils/issues/537 IC_kwDOCGYnMM5bva6L simonw 9599 2023-05-08T22:45:09Z 2023-05-08T22:45:21Z OWNER

Here's an example from the new tests:

https://github.com/simonw/sqlite-utils/blob/a75abeb61b91a28650d3b9933e7ec80ad0d92529/tests/test_create.py#L291-L307

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Support self-referencing FKs in `Table.create` 1665200812  
1539109816 https://github.com/simonw/sqlite-utils/issues/448#issuecomment-1539109816 https://api.github.com/repos/simonw/sqlite-utils/issues/448 IC_kwDOCGYnMM5bvPO4 simonw 9599 2023-05-08T22:01:00Z 2023-05-08T22:01:00Z OWNER

This is being handled in: - #520

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Reading rows from a file => AttributeError: '_io.StringIO' object has no attribute 'readinto' 1279144769  
1539109587 https://github.com/simonw/sqlite-utils/issues/520#issuecomment-1539109587 https://api.github.com/repos/simonw/sqlite-utils/issues/520 IC_kwDOCGYnMM5bvPLT simonw 9599 2023-05-08T22:00:46Z 2023-05-08T22:00:46Z OWNER

Hey, isn't this essentially the same issue as #448 ?

Yes it is, good catch!

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
rows_from_file() raises confusing error if file-like object is not in binary mode 1516644980  
1539108140 https://github.com/simonw/sqlite-utils/issues/525#issuecomment-1539108140 https://api.github.com/repos/simonw/sqlite-utils/issues/525 IC_kwDOCGYnMM5bvO0s simonw 9599 2023-05-08T21:59:41Z 2023-05-08T21:59:41Z OWNER

That original example passes against main now.

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Repeated calls to `Table.convert()` fail 1575131737  
1539101853 https://github.com/simonw/sqlite-utils/issues/525#issuecomment-1539101853 https://api.github.com/repos/simonw/sqlite-utils/issues/525 IC_kwDOCGYnMM5bvNSd simonw 9599 2023-05-08T21:52:44Z 2023-05-08T21:52:44Z OWNER

I like the lambda-{uuid} idea.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Repeated calls to `Table.convert()` fail 1575131737  
1539100300 https://github.com/simonw/sqlite-utils/issues/514#issuecomment-1539100300 https://api.github.com/repos/simonw/sqlite-utils/issues/514 IC_kwDOCGYnMM5bvM6M simonw 9599 2023-05-08T21:50:51Z 2023-05-08T21:50:51Z OWNER

Seeing as sqlite-utils doesn't currently provide mechanisms for adding check constraints like this I'm going to leave this - I'm happy with the fix I put in for the not null constraints.

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
upsert of new row with check constraints fails 1465194249  
1539099703 https://github.com/simonw/sqlite-utils/issues/514#issuecomment-1539099703 https://api.github.com/repos/simonw/sqlite-utils/issues/514 IC_kwDOCGYnMM5bvMw3 simonw 9599 2023-05-08T21:50:06Z 2023-05-08T21:50:06Z OWNER

Applying the fix from the PR here doesn't fix the above problem either: - https://github.com/simonw/sqlite-utils/pull/515

So it looks like these kinds of check constraints currently aren't compatible with how upsert() works.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
upsert of new row with check constraints fails 1465194249  
1539094287 https://github.com/simonw/sqlite-utils/issues/514#issuecomment-1539094287 https://api.github.com/repos/simonw/sqlite-utils/issues/514 IC_kwDOCGYnMM5bvLcP simonw 9599 2023-05-08T21:44:11Z 2023-05-08T21:44:11Z OWNER

OK, this fails silently: python import sqlite_utils db = sqlite_utils.Database(memory=True) db.execute('''CREATE TABLE employees ( id INTEGER PRIMARY KEY, name TEXT, age INTEGER, salary REAL, CHECK (salary is not null and salary > 0) );''') db["employees"].upsert({"id": 1, "name": "Bob"}, pk="id") list(db["employees"].rows) ```` It outputs:python [] ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
upsert of new row with check constraints fails 1465194249  
1539079507 https://github.com/simonw/sqlite-utils/issues/514#issuecomment-1539079507 https://api.github.com/repos/simonw/sqlite-utils/issues/514 IC_kwDOCGYnMM5bvH1T simonw 9599 2023-05-08T21:28:37Z 2023-05-08T21:28:37Z OWNER

This means that a table with NON NULL (or other constraint) columns that aren't part of the pkey can't have new rows upserted.

Huh... on that basis, it's possible my fix in https://github.com/simonw/sqlite-utils/commit/2376c452a56b0c3e75e7ca698273434e32945304 is incomplete. I only covered the 'not null' case.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
upsert of new row with check constraints fails 1465194249  
1539078429 https://github.com/simonw/sqlite-utils/issues/514#issuecomment-1539078429 https://api.github.com/repos/simonw/sqlite-utils/issues/514 IC_kwDOCGYnMM5bvHkd simonw 9599 2023-05-08T21:27:40Z 2023-05-08T21:27:40Z OWNER

Dupe of: - #538

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
upsert of new row with check constraints fails 1465194249  
1539077777 https://github.com/simonw/sqlite-utils/pull/515#issuecomment-1539077777 https://api.github.com/repos/simonw/sqlite-utils/issues/515 IC_kwDOCGYnMM5bvHaR simonw 9599 2023-05-08T21:27:10Z 2023-05-08T21:27:10Z OWNER

I should have spotted this PR before I shipped my own fix! https://github.com/simonw/sqlite-utils/commit/2376c452a56b0c3e75e7ca698273434e32945304

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
upsert new rows with constraints, fixes #514 1465194930  
1539058795 https://github.com/simonw/sqlite-utils/pull/519#issuecomment-1539058795 https://api.github.com/repos/simonw/sqlite-utils/issues/519 IC_kwDOCGYnMM5bvCxr simonw 9599 2023-05-08T21:12:52Z 2023-05-08T21:12:52Z OWNER

This is a really neat fix, thank you.

{
    "total_count": 1,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 1,
    "rocket": 0,
    "eyes": 0
}
Fixes breaking DEFAULT values 1505568103  
1539055393 https://github.com/simonw/sqlite-utils/pull/537#issuecomment-1539055393 https://api.github.com/repos/simonw/sqlite-utils/issues/537 IC_kwDOCGYnMM5bvB8h simonw 9599 2023-05-08T21:10:06Z 2023-05-08T21:10:06Z OWNER

Thanks!

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Support self-referencing FKs in `Table.create` 1665200812  
1539053230 https://github.com/simonw/sqlite-utils/pull/528#issuecomment-1539053230 https://api.github.com/repos/simonw/sqlite-utils/issues/528 IC_kwDOCGYnMM5bvBau simonw 9599 2023-05-08T21:08:23Z 2023-05-08T21:08:23Z OWNER

I fixed this in: - #527

Will fully remove this misfeature in: - #542

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Enable `Table.convert()` on falsey values 1578793661  
1539052467 https://github.com/simonw/sqlite-utils/issues/542#issuecomment-1539052467 https://api.github.com/repos/simonw/sqlite-utils/issues/542 IC_kwDOCGYnMM5bvBOz simonw 9599 2023-05-08T21:07:41Z 2023-05-08T21:07:41Z OWNER

Relevant commits (will mostly revert these): - https://github.com/simonw/sqlite-utils/commit/455c35b512895c19bf922c2b804d750d27cb8dbd - https://github.com/simonw/sqlite-utils/commit/e0ec4c345129996011951e400388fd74865f65a2

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Remove `skip_false=True` and `--no-skip-false` in `sqlite-utils` 4.0 1700936245  
1539051724 https://github.com/simonw/sqlite-utils/issues/527#issuecomment-1539051724 https://api.github.com/repos/simonw/sqlite-utils/issues/527 IC_kwDOCGYnMM5bvBDM simonw 9599 2023-05-08T21:07:04Z 2023-05-08T21:07:04Z OWNER

Updated documentation: - https://sqlite-utils.datasette.io/en/latest/python-api.html#converting-data-in-columns - https://sqlite-utils.datasette.io/en/latest/cli.html#converting-data-in-columns - https://sqlite-utils.datasette.io/en/latest/cli-reference.html#convert

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`Table.convert()` skips falsey values 1578790070  
1539035838 https://github.com/simonw/sqlite-utils/issues/527#issuecomment-1539035838 https://api.github.com/repos/simonw/sqlite-utils/issues/527 IC_kwDOCGYnMM5bu9K- simonw 9599 2023-05-08T20:55:00Z 2023-05-08T20:55:00Z OWNER

I'm going to go with --no-skip-false as the CLI option. It's ugly, but this whole thing is ugly. I'm going to make a note to remove this misfeature in sqlite-utils 4.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`Table.convert()` skips falsey values 1578790070  
1539033736 https://github.com/simonw/sqlite-utils/issues/527#issuecomment-1539033736 https://api.github.com/repos/simonw/sqlite-utils/issues/527 IC_kwDOCGYnMM5bu8qI simonw 9599 2023-05-08T20:52:51Z 2023-05-08T20:52:51Z OWNER

OK, I implemented that at the Python API level. I need to decide how it should work for the sqlite-utils convert command too: https://sqlite-utils.datasette.io/en/stable/cli-reference.html#convert

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`Table.convert()` skips falsey values 1578790070  
1539018912 https://github.com/simonw/sqlite-utils/issues/530#issuecomment-1539018912 https://api.github.com/repos/simonw/sqlite-utils/issues/530 IC_kwDOCGYnMM5bu5Cg simonw 9599 2023-05-08T20:39:00Z 2023-05-08T20:39:00Z OWNER

I think the natural place to add these in the Python library API would be https://sqlite-utils.datasette.io/en/stable/python-api.html#adding-foreign-key-constraints - maybe something like this:

python db["books"].add_foreign_key("author_id", "authors", "id", on_delete=RESTRICT)

Then for the CLI tool could be added to https://sqlite-utils.datasette.io/en/stable/cli-reference.html#add-foreign-key

sqlite-utils add-foreign-key my.db books author_id authors id --on-update SET_NULL I wouldn't support these for the other methods of adding foreign keys - foreign_keys(...) for the various .insert() etc methods and the add_foreign_keys(...) bulk menthod.

{
    "total_count": 1,
    "+1": 0,
    "-1": 0,
    "laugh": 1,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
add ability to configure "on delete" and "on update" attributes of foreign keys: 1595340692  
1539015064 https://github.com/simonw/sqlite-utils/issues/530#issuecomment-1539015064 https://api.github.com/repos/simonw/sqlite-utils/issues/530 IC_kwDOCGYnMM5bu4GY simonw 9599 2023-05-08T20:35:07Z 2023-05-08T20:35:07Z OWNER

Wow, this is a neat feature I didn't know about. Looks like there are a bunch of options:

  • NO ACTION (default)
  • RESTRICT: application is prohibited from deleting a parent key when there exists one or more child keys mapped to it
  • SET NULL: when a parent key is deleted the child key columns of all rows in the child table that mapped to the parent key are set to contain SQL NULL values
  • SET DEFAULT: set a specific default
  • CASCADE: propagates the delete or update operation on the parent key to each dependent child key
{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
add ability to configure "on delete" and "on update" attributes of foreign keys: 1595340692  
1539009453 https://github.com/simonw/sqlite-utils/issues/532#issuecomment-1539009453 https://api.github.com/repos/simonw/sqlite-utils/issues/532 IC_kwDOCGYnMM5bu2ut simonw 9599 2023-05-08T20:30:29Z 2023-05-08T20:30:42Z OWNER

Here's an improvement: ``` % sqlite-utils insert /tmp/b.db blah /tmp/blah.txt [####################################] 100% Error: Invalid JSON - use --csv for CSV or --tsv for TSV files

JSON error: Expecting value: line 1 column 1 (char 0) ```

{
    "total_count": 1,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 1,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Show more information when JSON can't be imported with sqlite-utils insert 1620254998  
1539006509 https://github.com/simonw/sqlite-utils/issues/532#issuecomment-1539006509 https://api.github.com/repos/simonw/sqlite-utils/issues/532 IC_kwDOCGYnMM5bu2At simonw 9599 2023-05-08T20:28:56Z 2023-05-08T20:28:56Z OWNER

Was this a newline-delimited JSON file perhaps?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Show more information when JSON can't be imported with sqlite-utils insert 1620254998  
1538963959 https://github.com/simonw/sqlite-utils/issues/541#issuecomment-1538963959 https://api.github.com/repos/simonw/sqlite-utils/issues/541 IC_kwDOCGYnMM5burn3 simonw 9599 2023-05-08T19:59:34Z 2023-05-08T19:59:34Z OWNER

There are 8 failing tests left:

==== short test summary info ==== FAILED tests/test_cli_memory.py::test_memory_csv[False-test] - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]> FAILED tests/test_cli_memory.py::test_memory_csv[False-t] - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]> FAILED tests/test_cli_memory.py::test_memory_csv[False-t1] - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]> FAILED tests/test_cli_memory.py::test_memory_tsv[False] - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]> FAILED tests/test_cli_memory.py::test_memory_dump[extra_args0] - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]> FAILED tests/test_cli_memory.py::test_memory_two_files_with_same_stem - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]> FAILED tests/test_recipes.py::test_dateparse_errors[None-parsedate] - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <function Table.convert.<locals>.convert_value at 0x106bcaca0> FAILED tests/test_recipes.py::test_dateparse_errors[None-parsedatetime] - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <function Table.convert.<locals>.convert_value at 0x106bc9620> ERROR tests/test_cli.py::test_upsert_analyze - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]> ==== 8 failed, 894 passed, 4 skipped, 1 error in 6.27s ==== Full traceback here: https://gist.github.com/simonw/b40b3e814729d6c02a0302a84ce54d9e

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
Get tests to pass with `pytest -Werror` 1700840265  
1538933540 https://github.com/simonw/sqlite-utils/issues/534#issuecomment-1538933540 https://api.github.com/repos/simonw/sqlite-utils/issues/534 IC_kwDOCGYnMM5bukMk simonw 9599 2023-05-08T19:34:37Z 2023-05-08T19:34:37Z OWNER

On macOS this shows the same warning: % python -Wdefault $(which sqlite-utils) insert dogs.db dogs dogs.csv --csv [############------------------------] 35% [####################################] 100%/Users/simon/Dropbox/Development/sqlite-utils/sqlite_utils/cli.py:1187: ResourceWarning: unclosed file <_io.TextIOWrapper name='dogs.csv' encoding='utf-8-sig'> insert_upsert_implementation( ResourceWarning: Enable tracemalloc to get the object allocation traceback The file itself is a click.File which is automatically closed - https://click.palletsprojects.com/en/8.1.x/api/#click.File - but it looks like it's the _io.TextIOWrapper which is not being closed:

https://github.com/simonw/sqlite-utils/blob/2376c452a56b0c3e75e7ca698273434e32945304/sqlite_utils/cli.py#L949-L956

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
ResourceWarning: unclosed file 1622640374  
1538921774 https://github.com/simonw/sqlite-utils/issues/538#issuecomment-1538921774 https://api.github.com/repos/simonw/sqlite-utils/issues/538 IC_kwDOCGYnMM5buhUu simonw 9599 2023-05-08T19:24:41Z 2023-05-08T19:24:41Z OWNER

That fix seems to work!

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`table.upsert_all` fails to write rows when `not_null` is present 1695428235  
1538910894 https://github.com/simonw/sqlite-utils/issues/538#issuecomment-1538910894 https://api.github.com/repos/simonw/sqlite-utils/issues/538 IC_kwDOCGYnMM5buequ simonw 9599 2023-05-08T19:16:52Z 2023-05-08T19:17:00Z OWNER

How about if I had logic which checked that all not-null columns were provided in the call to upsert_all() - and if they were, modified the INSERT OR IGNORE INTO to include a placeholder value for those columns that would then be fixed by the later UPDATE?

Something like this:

python [ ('INSERT OR IGNORE INTO [comments]([id], name) VALUES(?, ?);', [1, '']), ('UPDATE [comments] SET [name] = ? WHERE [id] = ?', ['Cleo', 1]) ]

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`table.upsert_all` fails to write rows when `not_null` is present 1695428235  
1538903556 https://github.com/simonw/sqlite-utils/issues/538#issuecomment-1538903556 https://api.github.com/repos/simonw/sqlite-utils/issues/538 IC_kwDOCGYnMM5buc4E simonw 9599 2023-05-08T19:11:24Z 2023-05-08T19:13:23Z OWNER

I could detect if this happens using cursor.rowcount - not sure how I would recover from it though.

This would also require some major re-engineering, since currently it all works by generating a list of SQL queries in advance and applying them inside a loop in .insert_chunk():

https://github.com/simonw/sqlite-utils/blob/80763edaa2bdaf1113717378b8d62075c4dcbcfb/sqlite_utils/db.py#L2839-L2878

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`table.upsert_all` fails to write rows when `not_null` is present 1695428235  
1538893329 https://github.com/simonw/sqlite-utils/issues/538#issuecomment-1538893329 https://api.github.com/repos/simonw/sqlite-utils/issues/538 IC_kwDOCGYnMM5buaYR simonw 9599 2023-05-08T19:04:47Z 2023-05-08T19:04:47Z OWNER

This feels like a fundamental flaw in the way upserts are implemented by sqlite-utils.

One fix would be to switch to using the UPSERT feature in SQLite: https://www.sqlite.org/lang_UPSERT.html

But...

UPSERT syntax was added to SQLite with version 3.24.0 (2018-06-04).

I still want to support SQLite versions earlier than that.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`table.upsert_all` fails to write rows when `not_null` is present 1695428235  
1538889482 https://github.com/simonw/sqlite-utils/issues/538#issuecomment-1538889482 https://api.github.com/repos/simonw/sqlite-utils/issues/538 IC_kwDOCGYnMM5buZcK simonw 9599 2023-05-08T19:02:38Z 2023-05-08T19:02:38Z OWNER

Here's the code at fault: https://github.com/simonw/sqlite-utils/blob/80763edaa2bdaf1113717378b8d62075c4dcbcfb/sqlite_utils/db.py#L2774-L2788

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`table.upsert_all` fails to write rows when `not_null` is present 1695428235  
1538887361 https://github.com/simonw/sqlite-utils/issues/538#issuecomment-1538887361 https://api.github.com/repos/simonw/sqlite-utils/issues/538 IC_kwDOCGYnMM5buY7B simonw 9599 2023-05-08T19:01:20Z 2023-05-08T19:01:20Z OWNER

Here's the problem: python import sqlite3 db = sqlite3.connect(":memory:") db.execute('create table foo (id integer primary key, name not null)') db.execute('insert into foo (id) values (1)') Produces: IntegrityError: NOT NULL constraint failed: foo.name But this: python db.execute('insert or ignore into foo (id) values (1)') Completes without an exception.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`table.upsert_all` fails to write rows when `not_null` is present 1695428235  
1538801855 https://github.com/simonw/sqlite-utils/issues/538#issuecomment-1538801855 https://api.github.com/repos/simonw/sqlite-utils/issues/538 IC_kwDOCGYnMM5buEC_ simonw 9599 2023-05-08T18:00:17Z 2023-05-08T18:00:17Z OWNER

From time in the debugger, after creating the table it ends up doing this: (Pdb) queries_and_params [ ('INSERT OR IGNORE INTO [comments]([id]) VALUES(?);', [1]), ('UPDATE [comments] SET [name] = ? WHERE [id] = ?', ['Cleo', 1]) ]

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`table.upsert_all` fails to write rows when `not_null` is present 1695428235  
1538793817 https://github.com/simonw/sqlite-utils/issues/538#issuecomment-1538793817 https://api.github.com/repos/simonw/sqlite-utils/issues/538 IC_kwDOCGYnMM5buCFZ simonw 9599 2023-05-08T17:55:10Z 2023-05-08T17:55:10Z OWNER

Confirmed - I added this test and it fails: python def test_upsert_all_not_null(fresh_db): # https://github.com/simonw/sqlite-utils/issues/538 fresh_db["comments"].upsert_all( [{"id": 1, "name": "Cleo"}], pk="id", not_null=["name"], ) assert list(fresh_db["comments"].rows) == [{"id": 1, "name": "Cleo"}]

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
`table.upsert_all` fails to write rows when `not_null` is present 1695428235  

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issue_comments] (
   [html_url] TEXT,
   [issue_url] TEXT,
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [created_at] TEXT,
   [updated_at] TEXT,
   [author_association] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [issue] INTEGER REFERENCES [issues]([id])
, [performed_via_github_app] TEXT);
CREATE INDEX [idx_issue_comments_issue]
                ON [issue_comments] ([issue]);
CREATE INDEX [idx_issue_comments_user]
                ON [issue_comments] ([user]);
Powered by Datasette · Queries took 641.789ms · About: github-to-sqlite