Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Nonetype object has no attribute write #841

Closed
abrichr opened this issue Jul 8, 2024 · 3 comments
Closed

[Bug]: Nonetype object has no attribute write #841

abrichr opened this issue Jul 8, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@abrichr
Copy link
Member

abrichr commented Jul 8, 2024

Describe the bug

Traceback (most recent call last):
  File "sqlalchemy\engine\base.py", line 1900, in _execute_context
  File "sqlalchemy\engine\default.py", line 736, in do_execute
sqlite3.InterfaceError: Error binding parameter 5 - probably unsupported type.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "multiprocessing\process.py", line 314, in _bootstrap
  File "multiprocessing\process.py", line 108, in run
  File "openadapt\utils.py", line 727, in wrapper_logging
    result = func(*args, **kwargs)
  File "openadapt\record.py", line 387, in write_events
    state = write_fn(session, recording, event, perf_q, **(state or {}))
  File "openadapt\record.py", line 315, in write_window_event
    crud.insert_window_event(db, recording, event.timestamp, event.data)
  File "openadapt\db\crud.py", line 154, in insert_window_event
    _insert(session, event_data, WindowEvent, window_events)
  File "openadapt\db\crud.py", line 80, in _insert
    result = session.execute(sa.insert(table), to_insert)
  File "sqlalchemy\orm\session.py", line 1714, in execute
  File "sqlalchemy\engine\base.py", line 1705, in _execute_20
  File "sqlalchemy\sql\elements.py", line 333, in _execute_on_connection
  File "sqlalchemy\engine\base.py", line 1572, in _execute_clauseelement
  File "sqlalchemy\engine\base.py", line 1943, in _execute_context
  File "sqlalchemy\engine\base.py", line 2124, in _handle_dbapi_exception
  File "sqlalchemy\util\compat.py", line 208, in raise_
  File "sqlalchemy\engine\base.py", line 1900, in _execute_context
  File "sqlalchemy\engine\default.py", line 736, in do_execute
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 5 - probably unsupported type.
[SQL: INSERT INTO window_event (id, recording_timestamp, recording_id, timestamp, state, title, "left", top, width, height, window_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: (None, 1720455851.1191764, 4, 1720455870.9879966, '{"title": [""], "left": 1188, "top": 1377, "width": 864, "height": 303, "meta": {"class_name": "TaskListThumbnailWnd", "friendly_class_name": "ListBo ... (219 characters truncated) ... rd_focusable": true, "has_keyboard_focus": true, "automation_id": "", "column_count": 0, "item_count": 3, "columns": []}, "data": {}, "window_id": 0}', [''], 1188, 1377, 864, 303, 0)]
(Background on this error at: https://sqlalche.me/e/14/rvf5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "openadapt\entrypoint.py", line 7, in <module>
    multiprocessing.freeze_support()
  File "Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_multiprocessing.py", line 50, in _freeze_support
  File "multiprocessing\spawn.py", line 116, in spawn_main
  File "multiprocessing\spawn.py", line 129, in _main
  File "multiprocessing\process.py", line 329, in _bootstrap
AttributeError: 'NoneType' object has no attribute 'write'

To Reproduce

Download OpenAdapt 0.36.2, unzip, run, create a recording.

@abrichr abrichr added the bug Something isn't working label Jul 8, 2024
@KIRA009
Copy link
Contributor

KIRA009 commented Jul 8, 2024

@abrichr I wasn't able to reproduce the issue, but from the error message you posted it looks like the data coming from get_active_window_data is flawed in some cases.

[parameters: (None, 1720455851.1191764, 4, 1720455870.9879966, '{"title": [""], "left": 1188, "top": 1377,....

The title field should be a string and not an array, if you look at the end of the parameters list

 "item_count": 3, "columns": []}, "data": {}, "window_id": 0}', [''], 1188, 1377, 864, 303, 0)]

the [''] is the value of the title, which sqlite is rejecting, which causes an exception, which then causes the logging to fail, because the logging happens on a multiprocessing.Process, which doesn't have the sys.std overrides that we set at the beginning of the entrypoint.

I think we need to solve for both. Check if the title is an array, if so then extract the value, and also, find a way to pass the std overrides to all multiprocessing.Process opened

@abrichr
Copy link
Member Author

abrichr commented Jul 10, 2024

Thank you @KIRA009!

I think the first issue of checking if the title is an array may be solved by #842.

Can you lease look into the second issue? 🙏

@abrichr
Copy link
Member Author

abrichr commented Jul 15, 2024

One solution may be to spawn a terminal like we're doing on MacOS. If this is easiest, let's go with that.

Another one seems to be catching the exceptions and handling them. Instead of calling multiprocessing.Process directly, we can implement a function that wraps it in a try/catch. Apparently this results in a pickling error, in which case we should look into monkeypatching multiprocessing with a different pickling library. (@KIRA009 please push your attempt at this)

@KIRA009 KIRA009 mentioned this issue Jul 16, 2024
7 tasks
@abrichr abrichr closed this as completed Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants