Skip to content

Add find_by_name() to QuerysetEndpoint for content item lookup #1810

Description

@jacalata

Background

PR #1802 introduces ContentItem as a Protocol that marks the primary content types (workbooks, datasources, views, flows). These are also exactly the endpoints that support server-side name filtering via QuerySet.filter(name=...).

QuerysetEndpoint already has .filter(**kwargs) returning a lazy QuerySet. A find_by_name convenience method belongs on QuerysetEndpoint as a thin, consistent wrapper — visible wherever a consumer would naturally look for it.

Proposed API

# On QuerysetEndpoint[T]:
def find_by_name(self, name: str) -> list[T]:
    return list(self.filter(name=name))

Usage:

matches = server.workbooks.find_by_name("Sales Dashboard")
matches = server.datasources.find_by_name("Orders")
matches = server.users.find_by_name("jsmith")
matches = server.projects.find_by_name("Marketing")

Returns a list (may be empty, may have multiple matches for same-name items in different projects). The caller chooses how to handle ambiguity — for example, filtering by owner_id or project on the result. A separate projects.find_by_path("Marketing/Reports/Monthly") would handle the hierarchical case (separate issue).

Why QuerysetEndpoint and not individual endpoints

All endpoints that inherit QuerysetEndpoint already support server-side name filtering. Putting find_by_name on the base class means:

  • One implementation, consistent across all content types
  • No endpoint inherits it unless it already supports name filtering (non-QuerysetEndpoint endpoints like jobs simply don't have it)
  • Pairs naturally with the ContentItem Protocol from Add structural Protocol types for TSC item classes #1802find_by_name is meaningful precisely for the types that satisfy ContentItem

Context

tabcmd (tabcmd/commands/server.py) has a hand-rolled get_items_by_name() that does manual pagination + RequestOptions name filter. This is the pattern every TSC client ends up writing from scratch. Moving it to QuerysetEndpoint lets tabcmd and other clients delete their own copies.

Related: #1809 (CSV user import cleanup), #1802 (ContentItem Protocol).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions