Skip to content

Commit 8549e39

Browse files
SNOW-2100781: Fix use_virtual_url in GCS (#2320)
1 parent 0d79989 commit 8549e39

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1010
- v3.16(TBD)
1111
- Added basic arrow support for Interval types.
1212
- Fix `write_pandas` special characters usage in the location name.
13+
- Fix usage of `use_virtual_url` when building the location for gcs storage client.
1314

1415
- v3.15.0(Apr 29,2025)
1516
- Bumped up min boto and botocore version to 1.24.

src/snowflake/connector/gcs_storage_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def generate_file_url(
464464
use_virtual_url: bool = False,
465465
) -> str:
466466
gcs_location = SnowflakeGCSRestClient.get_location(
467-
stage_location, use_regional_url, region, endpoint
467+
stage_location, use_regional_url, region, endpoint, use_virtual_url
468468
)
469469
full_file_path = f"{gcs_location.path}{filename}"
470470

test/unit/test_gcs_client.py

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,64 +350,93 @@ def test_get_file_header_none_with_presigned_url(tmp_path):
350350

351351

352352
@pytest.mark.parametrize(
353-
"region,return_url,use_regional_url,endpoint,use_virtual_url",
353+
"region,return_url,use_regional_url,endpoint,use_virtual_url,complete_url",
354354
[
355355
(
356356
"US-CENTRAL1",
357357
"https://storage.us-central1.rep.googleapis.com",
358358
True,
359359
None,
360360
False,
361+
"https://storage.us-central1.rep.googleapis.com/location/filename",
361362
),
362363
(
363364
"ME-CENTRAL2",
364365
"https://storage.me-central2.rep.googleapis.com",
365366
True,
366367
None,
367368
False,
369+
"https://storage.me-central2.rep.googleapis.com/location/filename",
368370
),
369-
("US-CENTRAL1", "https://storage.googleapis.com", False, None, False),
370-
("US-CENTRAL1", "https://storage.googleapis.com", False, None, False),
371-
("US-CENTRAL1", "https://location.storage.googleapis.com", False, None, True),
372-
("US-CENTRAL1", "https://location.storage.googleapis.com", True, None, True),
373371
(
374372
"US-CENTRAL1",
375-
"https://overriddenurl.com",
373+
"https://storage.googleapis.com",
376374
False,
377-
"https://overriddenurl.com",
375+
None,
378376
False,
377+
"https://storage.googleapis.com/location/filename",
379378
),
380379
(
381380
"US-CENTRAL1",
382-
"https://overriddenurl.com",
381+
"https://storage.us-central1.rep.googleapis.com",
383382
True,
384-
"https://overriddenurl.com",
383+
None,
385384
False,
385+
"https://storage.us-central1.rep.googleapis.com/location/filename",
386386
),
387387
(
388388
"US-CENTRAL1",
389-
"https://overriddenurl.com",
389+
"https://location.storage.googleapis.com",
390+
False,
391+
None,
390392
True,
391-
"https://overriddenurl.com",
393+
"https://location.storage.googleapis.com/filename",
394+
),
395+
(
396+
"US-CENTRAL1",
397+
"https://location.storage.googleapis.com",
392398
True,
399+
None,
400+
True,
401+
"https://location.storage.googleapis.com/filename",
393402
),
394403
(
395404
"US-CENTRAL1",
396405
"https://overriddenurl.com",
397406
False,
398407
"https://overriddenurl.com",
399408
False,
409+
"https://overriddenurl.com/location/filename",
410+
),
411+
(
412+
"US-CENTRAL1",
413+
"https://overriddenurl.com",
414+
True,
415+
"https://overriddenurl.com",
416+
False,
417+
"https://overriddenurl.com/location/filename",
418+
),
419+
(
420+
"US-CENTRAL1",
421+
"https://overriddenurl.com",
422+
True,
423+
"https://overriddenurl.com",
424+
True,
425+
"https://overriddenurl.com/filename",
400426
),
401427
(
402428
"US-CENTRAL1",
403429
"https://overriddenurl.com",
404430
False,
405431
"https://overriddenurl.com",
406432
True,
433+
"https://overriddenurl.com/filename",
407434
),
408435
],
409436
)
410-
def test_url(region, return_url, use_regional_url, endpoint, use_virtual_url):
437+
def test_url(
438+
region, return_url, use_regional_url, endpoint, use_virtual_url, complete_url
439+
):
411440
gcs_location = SnowflakeGCSRestClient.get_location(
412441
stage_location="location",
413442
use_regional_url=use_regional_url,
@@ -417,6 +446,17 @@ def test_url(region, return_url, use_regional_url, endpoint, use_virtual_url):
417446
)
418447
assert gcs_location.endpoint == return_url
419448

449+
generated_url = SnowflakeGCSRestClient.generate_file_url(
450+
stage_location="location",
451+
filename="filename",
452+
use_regional_url=use_regional_url,
453+
region=region,
454+
endpoint=endpoint,
455+
use_virtual_url=use_virtual_url,
456+
)
457+
458+
assert generated_url == complete_url
459+
420460

421461
@pytest.mark.parametrize(
422462
"region,use_regional_url,return_value",

0 commit comments

Comments
 (0)