Skip to content

[py] Fix driver service stop when starting browser fails #15656

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

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

cgoldberg
Copy link
Contributor

@cgoldberg cgoldberg commented Apr 22, 2025

User description

🔗 Related Issues

Fixes an error introduced in #15636

💥 What does this PR do?

This PR fixes an issue when trying to stop the driver service if the browser fails to start. It makes sure the webdriver instance has a service attribute before calling service.stop()

🔄 Types of changes

  • Bug fix (backwards compatible)

PR Type

Bug fix


Description

  • Fixes driver service stop when browser start fails

  • Checks for service attribute before calling stop()


Changes walkthrough 📝

Relevant files
Bug fix
webdriver.py
Add attribute check before stopping driver service             

py/selenium/webdriver/remote/webdriver.py

  • Adds check for service attribute before stopping service
  • Prevents AttributeError if service is missing on failure
  • +1/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @selenium-ci selenium-ci added the C-py Python Bindings label Apr 22, 2025
    @qodo-merge-pro qodo-merge-pro bot added Review effort 1/5 and removed C-py Python Bindings labels Apr 22, 2025
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Learned
    best practice
    Use getattr() with a default value for more concise null checking of object attributes

    The null check is good, but the code could be more concise by using the
    getattr() function with a default value instead of hasattr() followed by a None
    check.

    py/selenium/webdriver/remote/webdriver.py [354-359]

     try:
         response = self.execute(Command.NEW_SESSION, caps)["value"]
         self.session_id = response.get("sessionId")
         self.caps = response.get("capabilities")
     except Exception:
    -    if hasattr(self, "service") and self.service is not None:
    -        self.service.stop()
    +    service = getattr(self, "service", None)
    +    if service is not None:
    +        service.stop()
         raise

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 6
    Low
    • More

    @cgoldberg cgoldberg merged commit 45dc304 into SeleniumHQ:trunk Apr 22, 2025
    7 checks passed
    @cgoldberg cgoldberg deleted the py-fix-service-stop-remote branch April 22, 2025 16:25
    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.

    2 participants