Query: contains doesn't work with long prefix that end with 1

未關閉
#680 0 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

@vinay-google 已經在處理了。

開始於 2023年2月2日。

評估

這個 Issue 還沒有評估資料。

描述

Summary

When querying using name contains option, if the prefix ends with '1' it fails for all words above 19 characters.
Escaping the "\1" somehow fixes it (why though)
Excluding it by cutting the prefix short: works.
Using the full file name: works

Expected Behavior

  • Get a list of files that have the prefix

Actual Behavior

  • Returns empty list

Steps to Reproduce the Problem

from google.oauth2.service_account import Credentials
from googleapiclient.discovery import build
from googleapiclient.http import MediaIoBaseDownload
import io


scoped_creds = Credentials.from_service_account_info(creds, scopes=SCOPES)

gdrive = build("drive", "v3", credentials=scoped_creds)

parent_id = ""
data = io.BytesIO()


file_metadata = {
    "name": "thistwentyletterword_20230122",
    # "mimeType": "application/vnd.google-apps.spreadsheet", 
    "parents": ["parent_id"]
}
media = MediaIoBaseUpload(data, mimetype="text/csv", resumable=True)
# pylint: disable=maybe-no-member
print(
    gdrive.files()
    .create(
        supportsAllDrives=True, body=file_metadata, media_body=media, fields="id"
    )
    .execute()
)

# -> {'id': 'long_generated_file_id'}

# search for file with 'thistwentyletterword_202301'
# adding more characters after the '1' fails as well as long as it's not the full file name.

print(
    gdrive.files()
    .list(
        spaces="drive",
        q=f"""\
            mimeType != 'application/vnd.google-apps.folder'\
            and name contains 'thistwentyletterword_202301'\
            and trashed=false
            """,
        fields="files(id, name, mimeType)",
    )
    .execute()
    .get("files")
)

# out-> []

# Escape the "\1"
print(
    gdrive.files()
    .list(
        spaces="drive",
        q=f"""\
            mimeType != 'application/vnd.google-apps.folder'\
            and name contains 'thistwentyletterword_20230\1'\
            and trashed=false
            """,
        fields="files(id, name, mimeType)",
    )
    .execute()
    .get("files")
)

# out-> [{'mimeType': 'text/csv', 'id': 'long_generated_file_id', 'name': 'thistwentyletterword_20230122'}]

Specifications

  • Python version (python --3.10.7)
  • OS (Mac/Linux/Windows)
主要語言
Python
星號
1.4k
分支
917
平均合併
3 分鐘
30 天內合併 PR
1

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

googleworkspace/python-samples 的其他 Issue

查看 googleworkspace/python-samples 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。