Skip to content

Commit 8f2e4b2

Browse files
authored
fix: Fix crash in Actor.push_data with PPE and a strict charging limit (#664)
- reported [via Slack](https://apify.slack.com/archives/CGZSN9DQC/p1762419168355659)
1 parent f462df3 commit 8f2e4b2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/apify/_actor.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,18 +614,20 @@ async def push_data(self, data: dict | list[dict], charged_event_name: str | Non
614614
else None
615615
)
616616

617+
# Push as many items as we can charge for
618+
pushed_items_count = min(max_charged_count, len(data)) if max_charged_count is not None else len(data)
619+
617620
dataset = await self.open_dataset()
618621

619-
if max_charged_count is not None and len(data) > max_charged_count:
620-
# Push as many items as we can charge for
621-
await dataset.push_data(data[:max_charged_count])
622-
else:
622+
if pushed_items_count < len(data):
623+
await dataset.push_data(data[:pushed_items_count])
624+
elif pushed_items_count > 0:
623625
await dataset.push_data(data)
624626

625627
if charged_event_name:
626628
return await self.get_charging_manager().charge(
627629
event_name=charged_event_name,
628-
count=min(max_charged_count, len(data)) if max_charged_count is not None else len(data),
630+
count=pushed_items_count,
629631
)
630632

631633
return None

0 commit comments

Comments
 (0)