Skip to content

Conversation

julien-lang
Copy link
Contributor

@julien-lang julien-lang commented Jun 18, 2025

This pull request introduces several updates to the authentication and logging modules, focusing on improving caching mechanisms, refining user interface behaviors, and enhancing logging functionality. The changes streamline the handling of user authentication data, optimize caching for YAML files, and improve logging output formatting. Additionally, there are adjustments to UI elements and method logic in the login dialog to provide a smoother user experience.

Authentication Updates

UI Enhancements

  • python/tank/authentication/login_dialog.py: Replaced _update_ui_according_to_site_support with _on_site_changed for better site change handling. Added a spinner to indicate site information retrieval and adjusted method logic to prevent redundant UI updates. [1] [2] [3] [4]

Logging Improvements

  • python/tank/log.py: Added a reset_logger method to allow resetting the logger instance and updated the log formatter to include timestamps for better traceability. [1] [2]

Code Cleanup and Clarifications

  • python/tank/authentication/shotgun_authenticator.py: Added TODO comments to clarify misleading method names and descriptions. [1] [2]
  • python/tank/authentication/site_info.py: Added TODO comments to suggest emitting signals for site info updates and consuming cache more effectively.This pull request introduces several changes across multiple files to improve caching mechanisms, streamline authentication flows, and enhance logging functionality. Key updates include the addition of caching for YAML file contents, modifications to host and login handling in the defaults manager, and adjustments to logging formats and methods.

Caching Improvements:

Authentication Flow Enhancements:

  • python/tank/authentication/defaults_manager.py: Improved handling of host and login values by introducing _host and _login attributes with default False values, ensuring consistent initialization and caching. Updated methods such as get_host and get_login to use these attributes for better performance. [1] [2] [3]
  • python/tank/authentication/login_dialog.py: Refactored site change handling in _on_site_changed and _toggle_web methods to prevent unnecessary updates and improve site selection logic. Deprecated unused methods and added more descriptive logging. [1] [2]

Logging Enhancements:

  • python/tank/log.py: Added a reset_logger method to allow resetting the singleton logger instance. Updated the log formatter in initialize_custom_handler to include timestamps for better traceability. [1] [2]

Miscellaneous Fixes:

self._user_settings = UserSettings()
self._system_settings = SystemSettings()
self._fixed_host = fixed_host
self._host = False # current value might be None
Copy link

Choose a reason for hiding this comment

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

Black would make changes.

@julien-lang julien-lang requested a review from Copilot June 18, 2025 22:11
Copilot

This comment was marked as outdated.

@julien-lang julien-lang force-pushed the ticket/SG-33297-review-authentication-ui-flow branch from 5d87509 to 0d61453 Compare June 19, 2025 14:58
@julien-lang julien-lang requested a review from Copilot June 19, 2025 14:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances performance and usability by introducing content caching, streamlining authentication defaults handling, and improving logging and UI flows.

  • Added a YAML content cache with automatic invalidation to reduce redundant file reads.
  • Cached default host and login values in the defaults manager for faster lookups.
  • Extended the logger with a reset method, timestamped log output, and refactored site-change and login dialog behaviors.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
python/tank/log.py Added reset_logger, adjusted formatter to include timestamps.
python/tank/authentication/site_info.py Left placeholder TODOs and commented-out debug/sleep code.
python/tank/authentication/shotgun_authenticator.py Inserted unprefixed TODO lines in get_default_user.
python/tank/authentication/session_cache.py Introduced _YML_CONMTENT_CACHE with timeout-based invalidation.
python/tank/authentication/login_dialog.py Refactored _on_site_changed, initialized spinner, early return in _toggle_web.
python/tank/authentication/defaults_manager.py Cached _host and _login values, updated getters/setters.
Comments suppressed due to low confidence (1)

python/tank/authentication/shotgun_authenticator.py:235

  • Uncommented TODO line causes syntax error; prefix with # or move into a proper comment or docstring.
        TODO this method's name and description is not accurate. This method tries to return the current user with credentials. ...


# example: [DEBUG tank.log] message message
formatter = logging.Formatter("[%(levelname)s %(name)s] %(message)s")
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

The new log formatter omits the logger name, which can make identifying the source module harder; consider including %(name)s in the format string.

Suggested change
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s")

Copilot uses AI. Check for mistakes.

Comment on lines 43 to 53
# logger.info("Sleep for 10s")
# time.sleep(30)
# logger.info("done sleeping")

Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

[nitpick] Remove or clarify commented-out debug code and stray TODO comments to improve readability and maintainability.

Suggested change
# logger.info("Sleep for 10s")
# time.sleep(30)
# logger.info("done sleeping")

Copilot uses AI. Check for mistakes.

Comment on lines +152 to +162
_YML_CONMTENT_CACHE = {}
_YML_CONMTENT_CACHE_TIMEOUT = 300 # 5 minutes

def _try_load_yaml_file(file_path):
global _YML_CONMTENT_CACHE
global _YML_CONMTENT_CACHE_TIMEOUT

cache = _YML_CONMTENT_CACHE.get(file_path, None)
if cache and (time.time() - _YML_CONMTENT_CACHE_TIMEOUT > cache.get("timeout", 0)):
try:
del(_YML_CONMTENT_CACHE[file_path])
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Typo in constant name _YML_CONMTENT_CACHE; 'CONMTENT' should be 'CONTENT' for clarity.

Suggested change
_YML_CONMTENT_CACHE = {}
_YML_CONMTENT_CACHE_TIMEOUT = 300 # 5 minutes
def _try_load_yaml_file(file_path):
global _YML_CONMTENT_CACHE
global _YML_CONMTENT_CACHE_TIMEOUT
cache = _YML_CONMTENT_CACHE.get(file_path, None)
if cache and (time.time() - _YML_CONMTENT_CACHE_TIMEOUT > cache.get("timeout", 0)):
try:
del(_YML_CONMTENT_CACHE[file_path])
_YML_CONTENT_CACHE = {}
_YML_CONTENT_CACHE_TIMEOUT = 300 # 5 minutes
def _try_load_yaml_file(file_path):
global _YML_CONTENT_CACHE
global _YML_CONTENT_CACHE_TIMEOUT
cache = _YML_CONTENT_CACHE.get(file_path, None)
if cache and (time.time() - _YML_CONTENT_CACHE_TIMEOUT > cache.get("timeout", 0)):
try:
del(_YML_CONTENT_CACHE[file_path])

Copilot uses AI. Check for mistakes.

)

def _toggle_web(self, method_selected=None):
return
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Early return at the start of _toggle_web prevents any logic from running, making the method effectively dead code; remove or adjust this return.

Suggested change
return

Copilot uses AI. Check for mistakes.

otherwise, create this change:

-from . import QtCore
+from tank.platform.qt import QtCore
uic script said:
> Warning: The name 'verticalLayout_2' (QVBoxLayout) is already in
> use, defaulting to 'verticalLayout_21'.
@julien-lang julien-lang force-pushed the ticket/SG-33297-review-authentication-ui-flow branch from 8c9e895 to b6d084d Compare June 20, 2025 20:57
@julien-lang julien-lang force-pushed the ticket/SG-33297-review-authentication-ui-flow branch from b6d084d to e41f258 Compare June 20, 2025 21:22
self.site_info = site_info


# what if url is empty or site_info is empty???
Copy link

Choose a reason for hiding this comment

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

too many blank lines (2)


self._on_site_changed() # trigger the first site info request


Copy link

Choose a reason for hiding this comment

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

Black would make changes.

return INFOS_CACHE[url][1]

def _retrieve_site_info(url, http_proxy=None):
"""
Copy link

Choose a reason for hiding this comment

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

over-indented


return INFOS_CACHE[url][1]

def _retrieve_site_info(url, http_proxy=None):
Copy link

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

INFOS_CACHE = {}


def get(url: str, http_proxy: str|None=None, cache_only=False) -> SiteInfo|None:
Copy link

Choose a reason for hiding this comment

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

missing whitespace around bitwise or shift operator
missing whitespace around parameter equals

return self._infos.get("authentication_app_session_launcher_enabled", False)

# Cache the servers infos for 30 seconds.
INFOS_CACHE_TIMEOUT = 30
Copy link

Choose a reason for hiding this comment

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

expected 2 blank lines after class or function definition, found 1

self._infos = {}

def reload(self, url, http_proxy=None):
class SiteInfo:
Copy link

Choose a reason for hiding this comment

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

Black would make changes.
expected 2 blank lines, found 1

# guess here.
prev_selected_method = session_cache.get_preferred_method(site)
else:
prev_selected_method = None
Copy link

Choose a reason for hiding this comment

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

local variable 'prev_selected_method' is assigned to but never used

)

def _toggle_web(self, method_selected=None):
def _update_login_page_ui(self, auth_method: int|None=None):
Copy link

Choose a reason for hiding this comment

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

missing whitespace around bitwise or shift operator
missing whitespace around parameter equals

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.

1 participant