ucbds-infra / otter-grader

A Python and R autograding solution
https://otter-grader.readthedocs.io
BSD 3-Clause "New" or "Revised" License
125 stars 65 forks source link

Error following #875 in JupyterLite #878

Open spring-haru opened 1 week ago

spring-haru commented 1 week ago

Describe the bug Thanks for quickly responding to #875 . But another error followed with the message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File /lib/python3.12/site-packages/nbformat/__init__.py:169, in read(fp, as_version, capture_validation_error, **kwargs)
    168 try:
--> 169     buf = fp.read()
    170 except AttributeError:

AttributeError: 'str' object has no attribute 'read'

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
Cell In[5], line 5
      3 import otter
      4 print(otter.__version__)
----> 5 grader = otter.Notebook("homework-demo.ipynb")

File /lib/python3.12/site-packages/otter/check/utils.py:241, in logs_event.<locals>.event_logger(wrapped, self, args, kwargs)
    239 except Exception as e:
    240     self._log_event(event_type, success=False, error=e)
--> 241     raise e
    243 if ret is None:
    244     ret = LoggedEventReturnValue(None)

File /lib/python3.12/site-packages/otter/check/utils.py:237, in logs_event.<locals>.event_logger(wrapped, self, args, kwargs)
    232 """
    233 Runs a method, catching any errors and logging the call. Returns the unwrapped return value
    234 of the wrapped function.
    235 """
    236 try:
--> 237     ret: Optional[LoggedEventReturnValue[T]] = wrapped(*args, **kwargs)
    239 except Exception as e:
    240     self._log_event(event_type, success=False, error=e)

File /lib/python3.12/site-packages/otter/check/notebook.py:142, in Notebook.__init__(self, nb_path, tests_dir, tests_url_prefix)
    138     self._notebook = self._config["notebook"]
    140 if self._notebook:
    141     self._nbmeta_config = NBMetadataConfig.from_notebook(
--> 142         nbf.read(self._notebook, nbf.NO_CONVERT)
    143     )
    144 else:
    145     self._nbmeta_config = NBMetadataConfig()

File /lib/python3.12/site-packages/nbformat/__init__.py:171, in read(fp, as_version, capture_validation_error, **kwargs)
    169     buf = fp.read()
    170 except AttributeError:
--> 171     with open(fp, encoding="utf8") as f:  # noqa: PTH123
    172         return reads(f.read(), as_version, capture_validation_error, **kwargs)
    174 return reads(buf, as_version, capture_validation_error, **kwargs)

FileNotFoundError: [Errno 44] No such file or directory: 'homework-demo.ipynb'

Versions Python 3.12.1 Otter-grader: 6.0.2

chrispyles commented 1 week ago

It looks like Otter can't find the notebook file, which is odd. Can you share the notebook and, if possible, a link to the JupyterLite instance you're using?

spring-haru commented 1 week ago

Thanks. Here is the link

https://haruyama-kobeu.github.io/jlite/lab/index.html

The file for students is also attached.

homework-demo.ipynb.txt

chrispyles commented 1 week ago

Does this issue keep happening if you refresh the page? When I tried, I didn't get the error the first time, then refreshed and got the error, and haven't gotten it again since. I'm not sure what the issue is but I don't think it's related to Otter.

spring-haru commented 1 week ago

I’m away from home now. I will come back to you later. Thanks anyway.

spring-haru commented 1 week ago

Deleting cache and refreshing, I found the similar behaviour as you described. I think I’ll wait and see for a bit. Thanks. You are very helpful!