Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

How to accurately obtain the number of bytes occupied by each operation?

30 views
Skip to first unread message

xiaochuan li

unread,
Apr 22, 2025, 12:24:42 AMApr 22
to Google Ads API and AdWords API Forum
```python
def chunk_operations_by_size(operations):
    current_chunk = []
    current_size = 0
    chunks = []

    for operation in operations:
        operation_size = operation.ByteSize()  # AttributeError: Unknown field for MutateOperation: ByteSize
        operation_size = protobuf_helpers.get_bytes_size(operation)  # Cannot find reference 'get_bytes_size' in 'protobuf_helpers.py'
        operation_size = len(operation.SerializeToString())  # AttributeError: Unknown field for MutateOperation: SerializeToString

        if operation_size > SAFE_BYTE_THRESHOLD:
            raise ValueError(
                f"Operation size {operation_size} exceeds maximum size {SAFE_BYTE_THRESHOLD}."
            )

        if current_size + operation_size > SAFE_BYTE_THRESHOLD:
            chunks.append(current_chunk)
            current_chunk = []
            current_size = 0

        current_chunk.append(operation)
        current_size += operation_size

    if current_chunk:
        chunks.append(current_chunk)

    return chunks
```

This code shows the effect of wanting to get the number of bytes for each operation and limiting its maximum number of bytes.
But I can't get the exact number of bytes for each operation because these three methods are not available:
```
operation_size = operation.ByteSize()  # AttributeError: Unknown field for MutateOperation: ByteSize
        operation_size = protobuf_helpers.get_bytes_size(operation)  # Cannot find reference 'get_bytes_size' in 'protobuf_helpers.py'
        operation_size = len(operation.SerializeToString())  # AttributeError: Unknown field for MutateOperation: SerializeToString
```
How can I get the exact number of bytes for each operation?

ps: Please don't ask me to provide logs anymore. I know the problem I encountered very well, that is, a single `AddBatchJobOperationsRequest` exceeds the byte size limit. I have to split operations, but now I can't get the size of each operation. So, please give me a direct solution on how to get the size of the operation, thank you!

Google Ads API Forum Advisor

unread,
Apr 22, 2025, 3:51:17 AMApr 22
to clixia...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for contacting the Google Ads API support team. 

Upon reviewing your concern, what I understand is that while executing a ‘AddBatchJobOperations’, you encountered some byte size limit related error. Because of this, you want to know bytes occupied for each batch job operation in Google Ads API. As per the API documentation, each AddBatchJobOperationsRequest has a maximum size of 10,484,504 bytes. If you exceed this, you will receive an INTERNAL_ERROR. In order to determine the size of the request before submitting, you can refer to the code present in the Limitations section.

I hope this clarifies your concern. Feel free to reach out for any further concerns/ queries.

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-04-22 07:50:29Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01qUXV1:ref" (ADR-00300599)



Reply all
Reply to author
Forward
0 new messages