Handle missing settingsversion. #1747

Closed
iljah wants to merge 1 commits from patch-1 into v0.6
iljah commented 2021-03-23 16:25:21 +01:00 (Migrated from github.com)

Otherwise I get this with python 3.8.7 when starting BM: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' (assuming changes in https://github.com/Bitmessage/PyBitmessage/pull/1746)

Otherwise I get this with python 3.8.7 when starting BM: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' (assuming changes in https://github.com/Bitmessage/PyBitmessage/pull/1746)
PeterSurda (Migrated from github.com) requested changes 2021-03-23 19:47:31 +01:00
PeterSurda (Migrated from github.com) left a comment

Look at the BMConfigDefaults dict inside src/bmconfigparser.py.

Look at the `BMConfigDefaults` dict inside `src/bmconfigparser.py`.
@ -130,2 +130,4 @@
config = BMConfigParser()
if not config.has_option('bitmessagesettings', 'settingsversion'):
config.set('bitmessagesettings', 'settingsversion', 1)
settingsversion = config.getint('bitmessagesettings', 'settingsversion')
PeterSurda (Migrated from github.com) commented 2021-03-23 19:46:56 +01:00

Better to just add a default value into src/bmconfigparser.py

Better to just add a default value into `src/bmconfigparser.py`
iljah (Migrated from github.com) reviewed 2021-03-23 20:35:17 +01:00
@ -130,2 +130,4 @@
config = BMConfigParser()
if not config.has_option('bitmessagesettings', 'settingsversion'):
config.set('bitmessagesettings', 'settingsversion', 1)
settingsversion = config.getint('bitmessagesettings', 'settingsversion')
iljah (Migrated from github.com) commented 2021-03-23 20:35:17 +01:00

Adding it like this at least doesn't help:

    "bitmessagesettings": {
        "settingsversion": 1,
        "maxaddrperstreamsend": 500,
Adding it like this at least doesn't help: ``` "bitmessagesettings": { "settingsversion": 1, "maxaddrperstreamsend": 500, ```
PeterSurda (Migrated from github.com) reviewed 2021-03-23 21:46:08 +01:00
@ -130,2 +130,4 @@
config = BMConfigParser()
if not config.has_option('bitmessagesettings', 'settingsversion'):
config.set('bitmessagesettings', 'settingsversion', 1)
settingsversion = config.getint('bitmessagesettings', 'settingsversion')
PeterSurda (Migrated from github.com) commented 2021-03-23 21:46:07 +01:00

Try using safeGetInt instead of getint in addition to adding the default value into the dict.

Try using `safeGetInt` instead of `getint` in addition to adding the default value into the dict.
iljah (Migrated from github.com) reviewed 2021-03-25 13:57:40 +01:00
@ -130,2 +130,4 @@
config = BMConfigParser()
if not config.has_option('bitmessagesettings', 'settingsversion'):
config.set('bitmessagesettings', 'settingsversion', 1)
settingsversion = config.getint('bitmessagesettings', 'settingsversion')
iljah (Migrated from github.com) commented 2021-03-25 13:57:40 +01:00

switching to safegetint makes no difference whether settingsversion is included in BMConfigDefaults or not. No idea what the underlying cause is but my proposed fix adds only two lines...

switching to safegetint makes no difference whether settingsversion is included in BMConfigDefaults or not. No idea what the underlying cause is but my proposed fix adds only two lines...
g1itch (Migrated from github.com) reviewed 2021-03-25 16:00:07 +01:00
@ -130,2 +130,4 @@
config = BMConfigParser()
if not config.has_option('bitmessagesettings', 'settingsversion'):
config.set('bitmessagesettings', 'settingsversion', 1)
settingsversion = config.getint('bitmessagesettings', 'settingsversion')
g1itch (Migrated from github.com) commented 2021-03-25 16:00:07 +01:00
settingsversion = config.safeGetInt('bitmessagesettings', 'settingsversion', 1)

No default or the default from BMConfigDefaults is a possible bonus of python3 configparser.

Again, please read the tests: https://github.com/Bitmessage/PyBitmessage/blob/v0.6/src/tests/test_config.py#L40
Current PyBitmessage code should pass the tests.

@PeterSurda FIXME: It is also considered to be an exceptional case in current code when you open an existing config and it has no settings version. That's why getint() was retained there I think.

```python settingsversion = config.safeGetInt('bitmessagesettings', 'settingsversion', 1) ``` No default or the default from `BMConfigDefaults` is a possible bonus of python3 configparser. Again, please read the tests: https://github.com/Bitmessage/PyBitmessage/blob/v0.6/src/tests/test_config.py#L40 Current PyBitmessage code should pass the tests. @PeterSurda FIXME: It is also considered to be an exceptional case in current code when you open an existing config and it has no settings version. That's why `getint()` was retained there I think.
iljah (Migrated from github.com) reviewed 2021-03-25 16:13:29 +01:00
@ -130,2 +130,4 @@
config = BMConfigParser()
if not config.has_option('bitmessagesettings', 'settingsversion'):
config.set('bitmessagesettings', 'settingsversion', 1)
settingsversion = config.getint('bitmessagesettings', 'settingsversion')
iljah (Migrated from github.com) commented 2021-03-25 16:13:29 +01:00

The code you give is one of the changes I tried with stated effect. To me looks like only error from tests is in Ui_MainWindow which isn't related to this as far as I can see. If you want me to make additional changes you'll have to be more specific than "rest the tests".

The code you give is one of the changes I tried with stated effect. To me looks like only error from tests is in Ui_MainWindow which isn't related to this as far as I can see. If you want me to make additional changes you'll have to be more specific than "rest the tests".
This repo is archived. You cannot comment on pull requests.
No description provided.