Skip to content

Conversation

@elnikkis
Copy link

@elnikkis elnikkis commented Dec 5, 2025

This PR fixes an UnboundLocalError that occurs when calling stream_public() and other streaming endpoints.

When calling mastodon.stream_public(), the following error is raised:

  Traceback (most recent call last):
    File "/home/nicky/repos/mastodon-crawler/mastodon_crawler/get_stream.py", line 151, in <module>
      crawl(args)
      ~~~~~^^^^^^
    File "/home/nicky/repos/mastodon-crawler/mastodon_crawler/get_stream.py", line 82, in crawl
      handle = func(listener, run_async=True, reconnect_async=True)
    File "/home/nicky/repos/mastodon-crawler/.venv/lib/python3.13/site-packages/decorator.py", line 235, in fun
      return caller(func, *(extras + args), **kw)
    File "/home/nicky/repos/mastodon-crawler/.venv/lib/python3.13/site-packages/mastodon/versions.py", line 50, in wrapper
      return function(self, *args, **kwargs)
    File "/home/nicky/repos/mastodon-crawler/.venv/lib/python3.13/site-packages/mastodon/streaming_endpoints.py", line 37, in stream_public
      return self.__stream(base, listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
             ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/nicky/repos/mastodon-crawler/.venv/lib/python3.13/site-packages/mastodon/internals.py", line 412, in __stream
      url = self.__get_streaming_base()
    File "/home/nicky/repos/mastodon-crawler/.venv/lib/python3.13/site-packages/mastodon/internals.py", line 389, in __get_streaming_base
      parse = urlparse(instance["urls"]["streaming_api"])
                       ^^^^^^^^
  UnboundLocalError: cannot access local variable 'instance' where it is not associated with a value

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.79%. Comparing base (e36237f) to head (2ac51ca).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #433   +/-   ##
=======================================
  Coverage   88.79%   88.79%           
=======================================
  Files          35       35           
  Lines        4821     4821           
=======================================
  Hits         4281     4281           
  Misses        540      540           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@halcy
Copy link
Owner

halcy commented Dec 6, 2025

huh! weird that that slipped through testing. I‘ll have a look next time I am working on mastopy (possibly tomorrow, though no promises) and merge and add a test to catch this if possible.

Thank you a lot for finding and fixing this, in any case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants