posit-dev / positron

Positron, a next-generation data science IDE
Other
2.46k stars 73 forks source link

Variables Pane stops updating when Duckdb relation object created in Python session #4777

Open etiowousoro opened 4 days ago

etiowousoro commented 4 days ago

System details:

Positron and OS details:

Positron Version: 2024.09.0 (Universal) build 45 Operating System: MacOS Sequoia

Interpreter details:

Python 3.12.0

Describe the issue:

Creating any DuckDB relational object in Python breaks the Variables pane in Positron. As soon as a Duckdb relation is saved as a variable in the python session, no more variables are captured in the positron Variables pane.

I have tried Positron on three different mac machines, and I have observed this exact behavior on every version of the public pre-release that I have had the chance to try. I have also observed this behavior on multiple versions of python (3.9.6, 3.11.7, 3.12.1).

Steps to reproduce the issue:

Here is a reproducible python sample script. Please run line by line in a Positron interactive session:

import duckdb
import pandas as pd

# Create a dictionary with the data
data = {
    'Fruit': ['apple', 'banana', 'cherry'],
    'Quantity': [10, 20, 30]
}
# `data` variable in VARIABLES pane

# Create a DataFrame from the dictionary
df = pd.DataFrame(data)
# `df` variable in VARIABLES pane

# Import data into Duckdb. Save as a relation variable
rel = duckdb.from_df(df)
# `rel` is NOT in VARIABLES pane
# VARIABLES Pane no longer updates 

# Create a second dataframe object
df2 = pd.DataFrame(data)
# Variable Pane still not updating

# Variables print successfully to console despite frozen VARIABLES pane
print(df)
print(rel)
print(df2)

Note how rel or df2 did not make it to the Variable pane

image

Expected or desired behavior:

I would expect to see both rel and df2 as variables in the Variables.

Were there any error messages in the UI, Output panel, or Developer Tools console?

If I hit the "Refresh Objects" button in the Variables pane, I receive the following error after a few seconds

Error refreshing variables: RPC timed out after 5 seconds: {"jsonrpc":"2.0","method":"list"} Error (-32603)

petetronic commented 3 days ago

Thank you @etiowousoro for logging this! I'm able to reproduce the issue. I see the following error in my Output pane's Console: Python 3.x (Pyenv) channel:

Python] [Comm] ERROR | Exception in comm_msg for positron-variables-python-3-8187cd03
[Python] Traceback (most recent call last):
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/variables.py", line 756, in _summarize_variable
[Python]     display_value, is_truncated = ins.get_display_value()
[Python]                                   ^^^^^^^^^^^^^^^^^^^^^^^
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/inspectors.py", line 114, in get_display_value
[Python]     return pretty_format(self.value, print_width, truncate_at)
[Python]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/utils.py", line 127, in pretty_format
[Python]     s = pprint.pformat(value, width=print_width, compact=True)
[Python]         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Python]   File "/Users/username/.pyenv/versions/3.11.7/lib/python3.11/pprint.py", line 62, in pformat
[Python]     underscore_numbers=underscore_numbers).pformat(object)
[Python]                                            ^^^^^^^^^^^^^^^
[Python]   File "/Users/username/.pyenv/versions/3.11.7/lib/python3.11/pprint.py", line 158, in pformat
[Python]     self._format(object, sio, 0, 0, {}, 0)
[Python]   File "/Users/username/.pyenv/versions/3.11.7/lib/python3.11/pprint.py", line 178, in _format
[Python]     p = self._dispatch.get(type(object).__repr__, None)
[Python]         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Python] TypeError: unhashable type: 'instancemethod'
[Python] 
[Python] During handling of the above exception, another exception occurred:
[Python] 
[Python] Traceback (most recent call last):
[Python]   File "/Users/username/.pyenv/versions/3.11.7/lib/python3.11/site-packages/comm/base_comm.py", line 290, in comm_msg
[Python]     comm.handle_msg(msg)
[Python]   File "/Users/username/.pyenv/versions/3.11.7/lib/python3.11/site-packages/comm/base_comm.py", line 185, in handle_msg
[Python]     self._msg_callback(msg)
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/positron_comm.py", line 187, in handle_msg
[Python]     callback(comm_msg, raw_msg)
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/variables.py", line 126, in handle_msg
[Python]     self._send_list()
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/variables.py", line 466, in _send_list
[Python]     filtered_variables = self._list_all_vars()
[Python]                          ^^^^^^^^^^^^^^^^^^^^^
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/variables.py", line 463, in _list_all_vars
[Python]     return _summarize_children(variables, MAX_ITEMS)
[Python]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/variables.py", line 811, in _summarize_children
[Python]     summary = _summarize_variable(child, value, display_name=display_name)
[Python]               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/variables.py", line 783, in _summarize_variable
[Python]     return Variable(
[Python]            ^^^^^^^^^
[Python]   File "/Applications/Positron.app/Contents/Resources/app/extensions/positron-python/python_files/positron/positron_ipykernel/_vendor/pydantic/main.py", line 341, in __init__
[Python]     raise validation_error
[Python] positron_ipykernel._vendor.pydantic.error_wrappers.ValidationError: 1 validation error for Variable
[Python] updated_time
petetronic commented 3 days ago

We also need to restore guard code such that any given variable that fails to be summarized does not break the summary of other variables.