Skip to content

Replace usage of connection proxy with the requests library. #3552

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

jamescrake-merani
Copy link
Contributor

@jamescrake-merani jamescrake-merani commented Jul 28, 2025

Description

This PR aims to fix #3420 by removing our reliance on the ConnectionProxy class, and instead use the get request function from the requests library.

How Has This Been Tested?

Tested on run.py, and the wheel. Unfortunately, I haven't been able to test on the installer as I'm not sure if there is a way to fake the version to an older one to test the popup menu. Does anyone know how to do this? It might be useful if we add a debug version override flag for this purpose.

Review Checklist:

Documentation (check at least one)

  • There is nothing that needs documenting
  • Documentation changes are in this PR
  • There is an issue open for the documentation (link?)

Installers

  • There is a chance this will affect the installers, if so
    • Windows installer (GH artifact) has been tested (installed and worked)
    • MacOSX installer (GH artifact) has been tested (installed and worked)
    • Wheels installer (GH artifact) has been tested (installed and worked)

Licensing (untick if necessary)

  • The introduced changes comply with SasView license (BSD 3-Clause)

@jamescrake-merani jamescrake-merani marked this pull request as ready for review July 29, 2025 10:34
@@ -640,26 +630,20 @@ def log_imported_packages(self):
"""
PackageGatherer().log_imported_packages()

def processVersion(self, version_info):
def processVersion(self, version_str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version_str is the return value from get_current_release_version(), which returns a tuple of (str, str, Version).
Here, you're treating this tuple as a string? Or as a dict in line 646?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version_info was originally a dictionary of the JSON fetched from the server. I was going to just make this method take in the string only, but it looks like I mistakenly read the return type of get_current_release_version as a string rather than a tuple. I've changed this so it takes the tuple in, and destructures it to get the necessary values.


version_string = version_info["version"]
url = version_info["download_url"]

return version_string, url, parse(version_string)


except ConnectionError:
Copy link
Member

@rozyczko rozyczko Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be requests.exceptions.ConnectionError?

https://stackoverflow.com/questions/16511337/correct-way-to-try-except-using-python-requests-module

Also, what's the advantage of having a separate except for it if you're just dropping it completely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes looks like I didn't import it properly.

I was trying to mimic the original behaviour where it would just fail silently if it failed to establish a connection. But now you point this out, I don't think this is good behaviour. I'll just remove this handle so we just always fail with an error.

logger.info("Connected to www.sasview.org. Received: %s", content)

version_info = json.loads(content)
response = requests.get(web.update_url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a timeout like you did before with config.UPDATE_TIMEOUT.
Otherwise, get will hang indefinitely since the default timeout is None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll reuse the value we already had from the config.

@rozyczko
Copy link
Member

Looks good, ready to merge after merge conflicts are resolved.

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

Successfully merging this pull request may close these issues.

New Version Available not working on MacOS
3 participants