Skip to content
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

[Bug] Passing in Throughput Object with offer_throughput #39937

Open
tvaron3 opened this issue Mar 4, 2025 · 2 comments
Open

[Bug] Passing in Throughput Object with offer_throughput #39937

tvaron3 opened this issue Mar 4, 2025 · 2 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@tvaron3
Copy link
Member

tvaron3 commented Mar 4, 2025

The following code snippet does not work. The throughput object currently only works for auto scale. For manual throughput passing in an int is the only option. The logic for parsing the auto scale properties should also be reviewed again.

collection = db_fixture.get_collection(client.get_database_client(DB_NAME), collection_name)

# get current collection throughput settings
current_throughput = collection.get_throughput()
print("Current throughput: ", current_throughput.offer_throughput)

new_throughput = ThroughputProperties(offer_throughput=2500)
update_throughput = collection.replace_throughput(new_throughput)

retrieve_throughput = collection.get_throughput()
assert getattr(retrieve_throughput, "offer_throughput") == getattr(new_throughput, "offer_throughput")

The behavior for the code above should be the same as the one below.

collection = db_fixture.get_collection(client.get_database_client(DB_NAME), collection_name)

# get current collection throughput settings
current_throughput = collection.get_throughput()
print("Current throughput: ", current_throughput.offer_throughput)

new_throughput = ThroughputProperties(offer_throughput=2500)
update_throughput = collection.replace_throughput(new_throughput.offer_throughput)

retrieve_throughput = collection.get_throughput()
assert getattr(retrieve_throughput, "offer_throughput") == getattr(new_throughput, "offer_throughput")
@tvaron3 tvaron3 added Client This issue points to a problem in the data-plane of the library. Cosmos labels Mar 4, 2025
@fredcohen-aa
Copy link

def _replace_throughput(
    throughput: Union[int, ThroughputProperties],
    new_throughput_properties: Dict[str, Any]
) -> None:
    if isinstance(throughput, int):
        new_throughput_properties["content"]["offerThroughput"] = throughput
    else:
        try:
            max_throughput = throughput.auto_scale_max_throughput
            increment_percent = throughput.auto_scale_increment_percent
            if max_throughput is not None:
                new_throughput_properties['content']['offerAutopilotSettings']['maxThroughput'] = max_throughput
                if increment_percent:
                    new_throughput_properties['content']['offerAutopilotSettings']['autoUpgradePolicy']['throughputPolicy']['incrementPercent'] = increment_percent  # pylint: disable=line-too-long
                if throughput.offer_throughput:
                    new_throughput_properties["content"]["offerThroughput"] = throughput.offer_throughput
        except AttributeError as e:
            raise TypeError("offer_throughput must be int or an instance of ThroughputProperties") from e

Looking more closely at the code I believe it's line 792 shouldn't be indented under the " if max_throughput is not None" If it were shifted left it could work as intended.

@pvaneck pvaneck added the Service Attention Workflow: This issue is responsible by Azure service team. label Mar 4, 2025
Copy link

github-actions bot commented Mar 4, 2025

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @AbhinavTrips @bambriz @Pilchie @pjohari-ms @simorenoh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos Service Attention Workflow: This issue is responsible by Azure service team.
Projects
Status: No status
Development

No branches or pull requests

4 participants