User comments in config file lost after writing to config via `pgcli`
See original GitHub issueDescription
First of all, thanks for a great tool, I use it a lot.
User comments to the pgcli config file are getting lost after the config file gets modified via pgcli
itself (e.g. adding a named query). According to https://github.com/dbcli/pgcli/issues/1162#issuecomment-740076796 they should remain. Additionally, all whitelines from at least the [named queries]
section onward get lost as well.
I can reproduce this on a clean virtualenv and with a fresh config
file.
Reproduce
Log from my reproduction attempts:
- Removed previous config file
- Created new temp virtualenv (using the system Python 3.6.9), installed new pgcli (
pip install pgcli
) - Started
pgcli
, this created a new config file - Config file (from
[named queries]
section onward; same goes for the config file snippets below) at this point:# Named queries are queries you can execute by name. [named queries] # DSN to call by -D option [alias_dsn] # example_dsn = postgresql://[user[:password]@][netloc][:port][/dbname] # Format for number representation # for decimal "d" - 12345678, ",d" - 12,345,678 # for float "g" - 123456.78, ",g" - 123,456.78 [data_formats] decimal = "" float = ""
- Save new named query from
pgcli
:\ns foo bar
. Config file snippet after this:[named queries] foo = bar [alias_dsn] [data_formats] decimal = "" float = ""
- NOTE: the “# Named queries are queries you can execute by name.” comment (and the preceding whiteline) above the
[named query]
section header is now gone as well (while the “# style classes for colored table output” comment aboveoutput.header = "#00ff5f bold"
remained in tact. As did all other comment and whitelines earlier in the file)
- NOTE: the “# Named queries are queries you can execute by name.” comment (and the preceding whiteline) above the
- Close
pgcli
(just in case), add user comment above thefoo = bar
named query entry. Config file snippet after this:[named queries] # My comment foo = bar [alias_dsn] [data_formats] decimal = "" float = ""
- Start
pgcli
again, add new named query:\ns bar SELECT 1
. Config file snippet after this:[named queries] foo = bar bar = SELECT 1 [alias_dsn] [data_formats] decimal = "" float = ""
- Close
pgcli
(just in case), add record and comment to[alias_dsn]
. Config file snippet after this:[named queries] foo = bar bar = SELECT 1 [alias_dsn] # I feel like I'm getting lost baz = postgresql://foo@localhost/postgres [data_formats] decimal = "" float = ""
- Start
pgcli
again, add new named query:\ns baz SELECT 2
. Config file snippet after this:[named queries] foo = bar bar = SELECT 1 baz = SELECT 2 [alias_dsn] baz = postgresql://foo@localhost/postgres [data_formats] decimal = "" float = ""
Did another quick test (only some of the steps from above) with a Python 3.9.0 (via pyenv
) temp virtualenv, same results. Tried this one with both a pip install pgcli
and a pip install git+https://github.com/dbcli/pgcli@master
.
The same happens in my proper config file using my proper pgcli
install, which contains many more named queries and DSN aliases.
Environment, verison info
-
OS: Ubuntu 18.04.5 (x64)
-
pgcli:
- In most of the tests above:
Server: PostgreSQL 9.6.13 Version: 3.1.0
- My proper install:
Version: 3.0.0
- In most of the tests above:
-
pip freeze
of my proper install:
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top GitHub Comments
I submitted a PR into ConfigObj repo. We’ll see what happens with that.
https://github.com/DiffSK/configobj/pull/212
Fixed via https://github.com/dbcli/pgcli/pull/1251.
This is by no means a perfect solution. I wish that configparser in stdlib supported comments on write, unfortunately it does not. I’d like to try and submit a PR to https://github.com/DiffSK/configobj to fix this issue, but it will not happen immediately.