Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{db}/_design_docs/queries gives back non design documents too with 'keys' property #2851

Closed
mojito317 opened this issue Apr 30, 2020 · 2 comments · Fixed by #4682
Closed

Comments

@mojito317
Copy link

Description

When I query design docs against {db}/_design_docs/queries with keys array that contains document id-s which are not design documents, response will have those non-design documents.

Steps to Reproduce

  1. Create database
curl --location --request PUT 'localhost:5984/trial' \
--header 'Authorization: Basic ***'
  1. Create a design doc and a non-design doc
curl --location --request POST 'localhost:5984/trial/_bulk_docs' \
--header 'Authorization: Basic ***' \
--header 'Content-Type: application/json' \
--data-raw '{
    "docs": [
        {
            "_id": "_design/user-emails",
            "views": {
                "getVerifiedEmails": {
                    "map": "function(doc) { if(doc.email_verified && doc.email_verified == true){\n  emit(doc.email, [doc.name, doc.email_verified, doc.joined]) }}"
                }
            }
        },
        {
            "_id": "abc123",
            "type": "user",
            "email": "amelie.smith@aol.com",
            "email_verified": true
        }
    ]
}'
  1. Query design docs with keys property:
curl --location --request POST 'localhost:5984/trial/_design_docs/queries' \
--header 'Authorization: Basic ***' \
--header 'Content-Type: application/json' \
--data-raw '{
    "queries": [
        {
            "keys": 
                ["abc123"]
        }
    ]
}'
  1. response for the latter request is:
{
    "results": [
        {
            "total_rows": 1,
            "offset": null,
            "rows": [
                {
                    "id": "abc123",
                    "key": "abc123",
                    "value": {
                        "rev": "1-3e0944abf21b22d8d6fe70002edc2e82"
                    }
                }
            ]
        }
    ]
}

Expected Behaviour

The response should contain nothing, like when I use the key property:

curl --location --request POST 'localhost:5984/trial/_design_docs/queries' \
--header 'Authorization: Basic ***' \
--header 'Content-Type: application/json' \
--data-raw '{
    "queries": [
        {
            "key": "abc123"
        }
    ]
}'

Response:

{
    "results": [
        {
            "total_rows": 1,
            "offset": 1,
            "rows": []
        }
    ]
}

Your Environment

{
    "couchdb": "Welcome",
    "version": "3.0.0",
    "git_sha": "03a77db6c",
    "uuid": "cffa3c2cc703d6caed7ec9a9f6d110e9",
    "features": [
        "access-ready",
        "partitioned",
        "pluggable-storage-engines",
        "reshard",
        "scheduler"
    ],
    "vendor": {
        "name": "The Apache Software Foundation"
    }
}
  • CouchDB version used: 3.0.0, 03a77db
  • Browser name and version: Postman Version 7.22.1 (7.22.1)
  • Operating system and version: macOS Catalina 10.15.4
@wohali
Copy link
Member

wohali commented Apr 30, 2020

paging @tonysun83 @garrensmith

@jiahuili430
Copy link
Contributor

jiahuili430 commented Apr 5, 2023

PR #4494 should have fixed this issue for single keys.

$ curl -X DELETE http://adm:pass@127.0.0.1:15984/db
$ curl -X PUT http://adm:pass@127.0.0.1:15984/db
{"ok":true}
$ curl -X POST http://adm:pass@127.0.0.1:15984/db/_bulk_docs'?=' \
       -H 'Content-Type: application/json' \
       -d '{"docs": [{"_id": "_design/user-emails","views": {"getVerifiedEmails": {"map": "function(doc) {if(doc.email_verified && doc.email_verified == true){\n  emit(doc.email, [doc.name, doc.email_verified, doc.joined]) }}"}}},{"_id": "abc123","type": "user","email": "amelie.smith@aol.com","email_verified": true}]}'
[{"ok":true,"id":"_design/user-emails","rev":"1-840ca986e193b3f5df84da0befe09af6"},{"ok":true,"id":"abc123","rev":"1-3e0944abf21b22d8d6fe70002edc2e82"}]
$ curl -X POST http://adm:pass@127.0.0.1:15984/db/_design_docs/queries'?=' \
       -H 'Content-Type: application/json' \
       -d '{"queries": [{"keys": ["abc123"]}]}'
{"results":[{"total_rows":1,"offset":1,"rows":[]}]}

jiahuili430 added a commit to jiahuili430/couchdb that referenced this issue Jul 20, 2023
Querying design/local docs with `keys` should only return design/local docs.

Fixed: apache#2851
nickva pushed a commit that referenced this issue Jul 20, 2023
Querying design/local docs with `keys` should only return design/local docs.

Fixed: #2851
big-r81 pushed a commit that referenced this issue Jul 23, 2023
Querying design/local docs with `keys` should only return design/local docs.

Fixed: #2851
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants