pyfa-org / Pyfa

Python fitting assistant, cross-platform fitting tool for EVE Online
GNU General Public License v3.0
1.61k stars 408 forks source link

Exception in exception when DB is not initialised yet #2295

Closed StinGer-ShoGuN closed 3 years ago

StinGer-ShoGuN commented 3 years ago

I run Pyfa from sources. After updating to v2.31.1 (git checkout v2.31.1), I could not start Pyfa anymore.

Starting it from the CLI, I got the error message shown below.

The "real" error (MemoryError) is irrelevant here: I was indeed low on memory because of a 💥 instant messaging program my company uses which leaks memory as hell !!!

The fix (really easy) is in PR #2294.

Bug Report

PS X:\XX\Pyfa> python.exe .\pyfa.py
Gamedata DB data version mismatch: needed 1853874, DB has None
Building gamedata DB...
processing evetypes
processing evegroups
processing evecategories
processing dogmaattributes
processing dogmatypeattributes
processing dynamicitemattributes
processing dogmaeffects
processing dogmatypeeffects
processing dogmaunits
processing marketgroups
processing metagroups
processing clonegrades
processing metadata
Error in sys.excepthook:
Traceback (most recent call last):
  File "X:\XX\Pyfa\gui\errorDialog.py", line 50, in HandleException
    cls.__frame = ErrorFrame(None)
  File "X:\XX\Pyfa\gui\errorDialog.py", line 73, in __init__
    time = datetime.datetime.fromtimestamp(int(gamedata_date)).strftime('%Y-%m-%d %H:%M:%S')
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Original exception was:
Traceback (most recent call last):
  File ".\pyfa.py", line 126, in <module>
    update_db()
  File "X:\XX\Pyfa\db_update.py", line 565, in update_db
    eos.db.gamedata_session.flush()
  File "X:\Python\3.6\lib\site-packages\sqlalchemy\orm\session.py", line 2171, in flush
    self._flush(objects)
  File "X:\Python\3.6\lib\site-packages\sqlalchemy\orm\session.py", line 2233, in _flush
    _state_mapper(state)._is_orphan(state) and state.has_identity)
  File "X:\Python\3.6\lib\site-packages\sqlalchemy\orm\mapper.py", line 1836, in _is_orphan
    state, key, optimistic=state.has_identity)
    return self.get_impl(key).hasparent(state, optimistic=optimistic)
  File "X:\Python\3.6\lib\site-packages\sqlalchemy\orm\attributes.py", line 493, in hasparent
    return state.parents.get(id(self.parent_token), optimistic) \
  File "X:\Python\3.6\lib\site-packages\sqlalchemy\util\langhelpers.py", line 764, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
MemoryError

Expected behavior:

The exception should have appeared in a pop-up window.

Actual behavior:

No window, no error, nothing !

Detailed steps to reproduce:

From my understanding after a quick look at the code, any exception occurring before gamedata_date is initialised will cause such a behaviour.

Fits involved in EFT format (Edit > To Clipboard > EFT):

None

Release or development git branch? Please note the release version or commit hash:

On git tag v2.31.1.

Operating system and version (eg: Windows 10, OS X 10.9, OS X 10.11, Ubuntu 16.10):

Windows 10 2004

Other relevant information:

Python 3.6 (yes, I know, I shall update) Probably outdated sqlalchemy as well 😄

StinGer-ShoGuN commented 3 years ago

I forgot to mention: this is an eos bug, not a Pyfa one. But it looks like all eos development is made in Pyfa, so I posted here. Am i right ?

DarkFenX commented 3 years ago

You are right that eos development is done here. But, let me take a closer look at this issue

DarkFenX commented 3 years ago

First of all: pyfa and eos are interconnected, i really doubt you can split them apart. It might be doable, but it is hard. It is a mess, but it is the way it is.

Now, to your fix.

time = datetime.datetime.fromtimestamp(int(gamedata_date)).strftime('%Y-%m-%d %H:%M:%S')
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

You change gamedata_version, but it clearly tells us about gamedata_date. Also, they are initialized as "", but it complains about it being None. I suspect that they are set as None in pyfa/eos/db/__init__.py, and are not filled by any actual data since the script fails. Correct fix would be to adjust error handler code so that it can take any value, including none, since there is no guarantee it will be a string with int.

DarkFenX commented 3 years ago

Fixed in 05ab2d47c7fd093847cf0752168acab9fe29e1ed

StinGer-ShoGuN commented 3 years ago

Ho damn, corrected the wrong line... I had an issue with my SSH and GPG keys and have recloned the repo. I probably did not retested before committing, my bad.

I looked at your fix: it was the other option but I was lazy. 😄

DarkFenX commented 3 years ago

Even if you fixed the correct line, the fix would not work, since those values were temporarily overwritten by None during initialization