Generate Tenant-Aware Query

Replace direct tenant data queries with app.tenant_db calls and tenant_id filters.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/ATXINVOX/frappe-microservices-poc --skill generate-tenant-aware-query
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Generate Tenant-Aware Query
Source: https://github.com/ATXINVOX/frappe-microservices-poc/tree/main/.cursor/skills/generate-tenant-query
Command: npx skills add https://github.com/ATXINVOX/frappe-microservices-poc --skill generate-tenant-aware-query

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Automatically enforces tenant isolation when querying across data stores to prevent cross-tenant data leakage and accidental data exposure.

Core Features & Use Cases

  • Tenant-aware querying via app.tenant_db patterns
  • Safe, parameterized SQL usage to prevent injection
  • Use cases include get_all, get_doc, insert_doc with tenant scoping

Quick Start

Integrate the tenant-aware querying pattern in services to ensure all data access is scoped to the current tenant.

Frequently Asked Questions about Generate Tenant-Aware Query

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce tenant isolation in Frappe database queries?

To enforce tenant isolation in Frappe database queries, replace direct database calls with app.tenant_db equivalents. This scopes all get_all, get_doc, and insert_doc operations to a single tenant by applying tenant_id filters, preventing cross-tenant data leakage.

What is tenant-aware querying and when is it needed?

Tenant-aware querying is a data access pattern that scopes all database operations to a specific tenant using tenant_id filters. It is needed in multi-tenant architectures to prevent accidental data exposure and cross-tenant data leakage across shared data stores.

How do I prevent cross-tenant data leakage in Frappe DB?

Prevent cross-tenant data leakage in Frappe DB by using app.tenant_db for data access. Require app.set_tenant_id before any queries to validate the tenant context, and use parameterized SQL to block injection attempts during tenant-scoped operations.

Do I need to set tenant_id manually before querying Frappe DB?

Yes, you must call app.set_tenant_id manually before any data access to validate the tenant context. This ensures the subsequent app.tenant_db queries automatically apply the correct tenant_id filters to scope operations safely.

What's the best way to scope Frappe get_all and get_doc calls to a single tenant?

The best way to scope get_all and get_doc calls to a single tenant is executing app.tenant_db equivalents instead of direct database access. This automatically enforces tenant_id filters and requires parameterized SQL for safe, isolated data retrieval.

Does tenant-aware querying support parameterized SQL in Frappe?

Yes, tenant-aware querying explicitly enforces parameterized SQL usage within app.tenant_db operations. This prevents SQL injection while ensuring all executed queries remain safely scoped to the validated tenant_id context.