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

Đang mở
#680 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@vinay-google đang làm issue này rồi.

Từ ngày 2/2/2023.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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)
Ngôn ngữ chính
Python
Star
1.4k
Fork
917
Merge trung bình
3 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của googleworkspace/python-samples

Tất cả issue của googleworkspace/python-samples

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.