Skip to content

Commit ba85aae

Browse files
committed
Fixing Zones
1 parent dac165f commit ba85aae

File tree

12 files changed

+1273
-179
lines changed

12 files changed

+1273
-179
lines changed

src/brightdata/client.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,12 @@ async def _ensure_zones(self) -> None:
225225
if self._zone_manager is None:
226226
self._zone_manager = ZoneManager(self.engine)
227227

228+
# Don't pass browser_zone to auto-creation because browser zones
229+
# require additional configuration and cannot be auto-created
228230
await self._zone_manager.ensure_required_zones(
229231
web_unlocker_zone=self.web_unlocker_zone,
230232
serp_zone=self.serp_zone,
231-
browser_zone=self.browser_zone
233+
browser_zone=None # Never auto-create browser zones
232234
)
233235
self._zones_ensured = True
234236

@@ -341,17 +343,23 @@ async def test_connection(self) -> bool:
341343
self._is_connected = False
342344
return False
343345

344-
async def get_account_info(self) -> AccountInfo:
346+
async def get_account_info(self, refresh: bool = False) -> AccountInfo:
345347
"""
346348
Get account information including usage, limits, and quotas.
347349
350+
Note: This method caches the result by default. For fresh zone data,
351+
use list_zones() instead, or pass refresh=True.
352+
348353
Retrieves:
349354
- Account status
350355
- Active zones
351356
- Usage statistics
352357
- Credit balance
353358
- Rate limits
354359
360+
Args:
361+
refresh: If True, bypass cache and fetch fresh data (default: False)
362+
355363
Returns:
356364
Dictionary with account information
357365
@@ -360,11 +368,18 @@ async def get_account_info(self) -> AccountInfo:
360368
APIError: If API request fails
361369
362370
Example:
371+
>>> # Cached version (fast)
363372
>>> info = await client.get_account_info()
364373
>>> print(f"Active zones: {len(info['zones'])}")
365-
>>> print(f"Credit balance: ${info['balance']}")
374+
375+
>>> # Fresh data (use this after creating/deleting zones)
376+
>>> info = await client.get_account_info(refresh=True)
377+
>>> print(f"Active zones: {len(info['zones'])}")
378+
379+
>>> # Or better: use list_zones() for current zone list
380+
>>> zones = await client.list_zones()
366381
"""
367-
if self._account_info is not None:
382+
if self._account_info is not None and not refresh:
368383
return self._account_info
369384

370385
try:
@@ -447,9 +462,14 @@ def _run_async_with_cleanup(self, coro):
447462
finally:
448463
loop.close()
449464

450-
def get_account_info_sync(self) -> AccountInfo:
451-
"""Synchronous version of get_account_info()."""
452-
return self._run_async_with_cleanup(self.get_account_info())
465+
def get_account_info_sync(self, refresh: bool = False) -> AccountInfo:
466+
"""
467+
Synchronous version of get_account_info().
468+
469+
Args:
470+
refresh: If True, bypass cache and fetch fresh data (default: False)
471+
"""
472+
return self._run_async_with_cleanup(self.get_account_info(refresh=refresh))
453473

454474
def test_connection_sync(self) -> bool:
455475
"""Synchronous version of test_connection()."""

src/brightdata/core/zone_manager.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ async def ensure_required_zones(
4747
"""
4848
Check if required zones exist and create them if they don't.
4949
50-
Note: Browser zones are NOT auto-created because they require additional
51-
configuration parameters (like "start" value) that vary by use case.
52-
Only unblocker and SERP zones are auto-created.
50+
Important: Only unblocker and SERP zones can be auto-created.
51+
Browser zones require additional configuration parameters (like "start" value)
52+
and must be created manually in the Bright Data dashboard.
5353
5454
Args:
55-
web_unlocker_zone: Web unlocker zone name
56-
serp_zone: SERP zone name (optional)
57-
browser_zone: Browser zone name (optional, but NOT auto-created)
55+
web_unlocker_zone: Web unlocker zone name (will be created if missing)
56+
serp_zone: SERP zone name (optional, will be created if missing)
57+
browser_zone: Browser zone name (NOT auto-created, pass None to skip)
5858
5959
Raises:
6060
ZoneError: If zone creation or validation fails
@@ -79,15 +79,9 @@ async def ensure_required_zones(
7979
zones_to_create.append((serp_zone, 'serp'))
8080
logger.info(f"Need to create SERP zone: {serp_zone}")
8181

82-
# Browser zones are NOT auto-created because they require additional
83-
# configuration (like "start" parameter) that we cannot provide automatically
84-
if browser_zone and browser_zone not in zone_names:
85-
logger.warning(
86-
f"Browser zone '{browser_zone}' does not exist. "
87-
f"Browser zones cannot be auto-created because they require "
88-
f"additional configuration parameters. Please create this zone "
89-
f"manually in the Bright Data dashboard."
90-
)
82+
# Browser zones are intentionally NOT checked here
83+
# They require additional configuration (like "start" parameter)
84+
# and must be created manually in the Bright Data dashboard
9185

9286
if not zones_to_create:
9387
logger.info("All required zones already exist")

tests/enes/delete_zone_demo.py

Lines changed: 0 additions & 157 deletions
This file was deleted.

0 commit comments

Comments
 (0)