Skip to content

Instantly share code, notes, and snippets.

@mephinet
Created January 4, 2024 11:36
Show Gist options
  • Save mephinet/7415a4641a65fbf0d51f0eae11ee21dc to your computer and use it in GitHub Desktop.
Save mephinet/7415a4641a65fbf0d51f0eae11ee21dc to your computer and use it in GitHub Desktop.
Reproducer for repeated metadata fetches by gspread-pandas
import logging
import pytest
from gspread_pandas import Spread
logging.basicConfig(level=logging.DEBUG)
SHEETID = "1sHawtVOpVoUonUg7O-vLweF9ate6da3HWC_VvDRp9W0"
SPREADURL = f"https://docs.google.com/spreadsheets/d/{SHEETID}"
def test_sheet_metadata_only_fetched_once(caplog):
caplog.set_level(logging.DEBUG, logger="urllib3.connectionpool")
gsc = Spread(spread=SPREADURL)
data1 = gsc.sheet_to_df(sheet="A")
data2 = gsc.sheet_to_df(sheet="B")
metadata_requests = [
r
for r in caplog.records
if f"GET /v4/spreadsheets/{SHEETID}?includeGridData=false" in r.getMessage()
]
assert len(metadata_requests) == 1, metadata_requests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment