question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

files().list(q="name contains 'substr'") only matches when the substr at the beginning of name or after a space

See original GitHub issue

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you’ve tried the usual “quick fixes”:

If you are still having issues, please be sure to include as much information as possible:

Environment details

  • OS type and version: Darwin Kernel Version 21.2.0
  • Python version: Python 3.9.10
  • pip version: pip 22.0.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
  • google-api-python-client version:
Name: google-api-python-client
Version: 2.36.0
Summary: Google API Client Library for Python
Home-page: https://github.com/googleapis/google-api-python-client/
Author: Google LLC
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: google-api-core, google-auth, google-auth-httplib2, httplib2, uritemplate
Required-by: 

Steps to reproduce

  1. crate a folder named SMITH_JOHN TAYLER_DAVID
  2. try to list the folder with service.files().list(q=f"mimeType = 'application/vnd.google-apps.folder' and name contains 'JOHN'")
  3. It will not show the folder. It only shows when using SMITH or TAYLOR

Code example

import os
import yaml
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

creds = None
scopes = ["https://www.googleapis.com/auth/drive"]

if os.path.exists("token.json"):
     creds = Credentials.from_authorized_user_file("token.json", scopes)
if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file("credentials.json", scopes)
        creds = flow.run_local_server(port=0)

with open("token.json", "w", encoding="utf-8") as token:
    token.write(creds.to_json())

service = build("drive", "v3", credentials=creds)

response = service.files().list(q=f"mimeType = 'application/vnd.google-apps.folder' and name contains 'SMITH'",
                                spaces = 'drive',
                                fields='nextPageToken, files(id, name)',
                                orderBy = 'name').execute()

Stack trace

# example

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
odoublewencommented, Mar 18, 2022

Ah I see. Thanks @michaelxwang , good to have that info and the reference here.

@parthea I think you can close this issue

0reactions
michaelxwangcommented, Mar 18, 2022

@odoublewen I created a bug report (https://issuetracker.google.com/issues/219091193), they say it is not a bug. Then I created a feature request: https://issuetracker.google.com/issues/220326928 , please star this feature request. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Drive API: "contains" does not match string ...
list (q="name contains 'MITH'") => No match! So looks like that I can only search word from the beginning of the folder name...
Read more >
Hundreds of useful examples
functx:index-of-match-first, The first position of a matching substring ... A list of namespaces used in element/attribute names in an XML fragment.
Read more >
XPath and XQuery Functions and Operators 3.1
[Definition] An expanded-QName is a value in the value space of the xs:QName datatype as defined in the XDM data model (see [XQuery...
Read more >
SUBSTRING function - Progress Documentation
The expression "FIXED" specifies that position is in character units and the length is in bytes, but directs SUBSTRING to yield only whole...
Read more >
9 Using XPath Functions
The following are some examples of XPath functions: ... Retrieves the substring of the first argument starting at the index of the second...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found