print cannot read items with numeric or hierarchical partition keys
Los mantenedores suelen responder en 2 días
Ya se ha fusionado un pull request relacionado.
- #248 de @mkrueger — fusionado
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
Línea de trabajo
Start in PrintCommand.cs: the PartitionKey property is typed as string and PrintItemAsync always builds new PartitionKey(this.PartitionKey). Read CreatePartitionKeyFromArgument, which rm, batch and stored procedures already use, to see how typed keys are parsed. Done when print reads the numeric 680 and string "680" documents with the same id separately, reads a mixed-type hierarchical key correctly, and keeps the not-found and input-error paths distinct. The end-to-end tests need an emulator or test account, and the typed-input syntax still has to be designed.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
print binds its partition-key argument to string and always constructs the Cosmos SDK string partition key. Numeric and hierarchical partition keys are valid in Cosmos DB for NoSQL, but this command cannot address them correctly. Both failures were observed in the same provisioning verification run.
Observed with Cosmos DB Shell 1.1.271-preview during Azure provisioning verification. The same implementation remains in the current source revision linked below. Typed SDK point reads succeeded for the inserted documents.
Example 1: Numeric Partition Key
Given a Products container in database Demo configured with partition-key path /productId, insert:
{
"id": "product-680",
"docType": "product",
"productId": 680,
"name": "Road Frame"
}
Then run:
print product-680 680 --database=Demo --container=Products
Actual: the command sends partition key "680" as a JSON string, not numeric 680. It addresses the wrong logical partition and reports that the item is not found.
Expected: provide an unambiguous way to supply a numeric partition key and return this document. Merely removing command-line quotes does not help while the argument is bound to a C# string.
The equivalent typed SDK read works:
using var response = await container.ReadItemStreamAsync(
"product-680", new PartitionKey(680d));
Example 2: Numeric-Looking String Must Remain Distinct
This is also a valid document in the same container:
{
"id": "product-680",
"docType": "product",
"productId": "680",
"name": "String-keyed product"
}
Numeric 680 and string "680" are different partition-key values. Both documents can use the same id because they occupy different logical partitions. With both present, the current implementation addresses the string-keyed document, even when the caller intends the numeric one.
A fix must preserve this distinction instead of guessing that every numeric-looking string should become a number. An explicit typed/JSON input mechanism is one option; its precise CLI syntax can be chosen as part of the fix.
Example 3: Mixed-Type Hierarchical Partition Key
Given a Customers container in database Demo with ordered hierarchical partition-key paths /customerId and /id, insert:
{
"id": "customer-1001",
"docType": "customer",
"customerId": 1001,
"name": "Example Customer"
}
The complete partition key is [1001, "customer-1001"]: a number followed by a string.
This attempted invocation on 1.1.271-preview failed:
print customer-1001 '[1001,"customer-1001"]' --database=Demo --container=Customers
Actual: the JSON-looking argument becomes one string-valued partition-key component, not two typed components. The observed read failed with HTTP 400. Changing outer quoting did not resolve it.
Expected: accept an explicitly typed, complete hierarchical key, preserve component order and types, and return the intended document. The command above records an attempted reproduction, not a requirement that this become the final supported syntax.
The equivalent typed SDK read succeeded:
var key = new PartitionKeyBuilder()
.Add(1001d)
.Add("customer-1001")
.Build();
using var response = await container.ReadItemStreamAsync("customer-1001", key);
The migration ultimately verified all 36 synthetic documents with typed SDK point reads; this fallback should not be necessary solely because their partition keys are non-string or hierarchical.
Root Cause
PrintCommand.PartitionKey is declared as string?, and PrintItemAsync calls:
new PartitionKey(this.PartitionKey)
That always selects the SDK string overload. The positional-argument binder first converts evaluated arguments to text, and print does not parse that text into typed scalar or hierarchical components.
The shared CreatePartitionKeyFromArgument helper already provides typed parsing for other commands, including rm, batch, and stored procedures. It is a reuse candidate, but adopting automatic parsing must not silently reinterpret existing numeric-looking string keys. The fix should define an explicit typed-input contract and validate supported components and complete hierarchical keys.
Source: PrintCommand.
Cosmos DB explicitly supports numeric partition-key values: partition-key documentation.
Impact and Acceptance Criteria
- Valid numeric-key and hierarchical-key documents cannot be reliably point-read with
print; migration verification had to use a separate typed SDK reader. - Support numeric keys and complete, ordered hierarchical keys without changing stored documents, IDs, partition-key types, or container definitions.
- Preserve existing string-key behavior, including numeric-looking string values.
- Add regression coverage for numeric and string keys with the same item ID, proving each read returns the intended document.
- Keep genuine missing-item errors distinct from input/type errors.
- Document the supported typed-input and quoting syntax in command help and examples, including how to request a numeric-looking string explicitly.
End-to-End Regression Coverage
Exercise the actual Shell parser, argument binding, command dispatch, and SDK point read against an emulator or isolated Cosmos DB for NoSQL test account. Use synthetic fixtures and independently verify their stored key types through the SDK. Parser-only, disconnected-state, and command-help checks are not sufficient.
- Numeric versus string: create documents with the same item ID and partition keys
680and"680", with different marker fields. Read each through the supported Shell syntax and assert the correct returned marker and JSON key type. - Hierarchical keys: cover two- and three-component keys mixing strings, numbers, and booleans. Include same-ID documents whose tuples differ only by a numeric versus string component; assert exact document selection, component order, and types.
- Other scalar forms: cover ordinary strings, explicitly typed booleans, and explicit null keys, retaining their distinction from the strings
"true"and"null". - Invalid and missing inputs: cover malformed typed JSON, object or nested-array components, and incomplete/extra hierarchical components. Report actionable input errors; a well-formed key for a missing item must still produce the normal not-found result.
- Provisioning verification: seed a mixed-key fixture set, run
printfor every expected(id, full partition key)pair, and compare returned document content with the fixtures, ignoring only service-generated metadata. Do not count a query fallback as a successful point read or rewrite stored keys to make the test pass.
Retain focused unit tests for key conversion and backward compatibility in addition to this end-to-end coverage.
This issue is separate from throughput authentication and the VS Code MCP transport-detection failure.
- Lenguaje dominante
- C#
- Estrellas
- 4
- Forks
- 7
- Merge medio
- 2 d 9 min
- PR fusionados (30 d)
- 29
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Azure/CosmosDBShell
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Azure/CosmosDBShell#240 ·
Los mantenedores suelen responder en 2 días
-
automation P1
Dificultad 5/5 Más de una semana Aptitud para principiantes 45/100
Azure/CosmosDBShell#178 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Lightweight headless CI distribution (no MCP, LSP, interactive UI)Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertoautomation P1
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Azure/CosmosDBShell#175 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
agentic enhancement P0
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
Azure/CosmosDBShell#153 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Azure/CosmosDBShell#104 · 8 comentarios ·
Los mantenedores suelen responder en 2 días
Todos los issues de Azure/CosmosDBShell
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
dette technique priorité: basse zone: service
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
damiensabau/nexus-lobby#25 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
sebastienros/jint#4282 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 76/100
pyrevitlabs/pyRevit#3792 ·
Los mantenedores suelen responder en 1 día