Skip to content

Issue in Python 3.11+ with setting base_url for GraphServiceClient #818

Closed

Description

I'm experiencing issues suddenly after updating to python 3.11, getting "Valid url scheme and host required" when trying to use the GraphServiceClient

I think I have narrowed it down to some strange handling of enums in graph_client_factory.py in _get_base_url in the f-string handling of enums

Running the following code:

from enum import Enum

class NationalClouds(str, Enum):
    Global = 'https://graph.microsoft.com'
    
    
print("print:", NationalClouds.Global)
print(f"f-string: {NationalClouds.Global}")

print("%%-formatting: %s" % NationalClouds.Global)

Yields

print: NationalClouds.Global
f-string: https://graph.microsoft.com
%-formatting: NationalClouds.Global

In 3.10 and earlier, but

print: NationalClouds.Global
f-string: NationalClouds.Global
%-formatting: NationalClouds.Global

So my base URL is being set to NationalClouds.Global/APIVersion.v1/

I don't feel confident in fixing this myself, but would like if anyone has any input on my issue.

Activity

  1. peter-equinor commented on Jan 30, 2025

    @peter-equinor
    Author

    This seems to have been listed as a change in python 3.11 here: https://docs.python.org/3/whatsnew/3.11.html#enum

    Changed Enum.format() (the default for format(), str.format() and f-strings) to always produce the same result as Enum.str(): for enums inheriting from ReprEnum it will be the member’s value; for all other enums it will be the enum and member name (e.g. Color.RED).

  2. peter-equinor commented on Jan 30, 2025

    @peter-equinor
    Author

    To reproduce:

    from msgraph_core.graph_client_factory import GraphClientFactory
    
    c = GraphClientFactory.create_with_default_middleware()
    
    print(c.base_url)

    Running this in python 3.11 and newer returns NationalClouds.Global/APIVersion.v1/

  3. chrizzo1984 commented on Jan 30, 2025

    @chrizzo1984
    Contributor

    Same problem here.
    The problem is now that it needs to be with .value.

  4. beko0014 commented on Jan 30, 2025

    @beko0014

    Same problem here.
    method create_with_default_middleware does not use value of Enums.

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

Metadata

Metadata

Labels

WIPbugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions