```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!

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/adwords-api/a0a022c1-af6d-4d15-bac7-2d09d42d3bden%40googlegroups.com.
  • Ho... xiaochuan li
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to