Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Make create_query_index always supply partitioned #470

Merged
merged 5 commits into from
May 14, 2020

Conversation

bessbd
Copy link
Contributor

@bessbd bessbd commented May 12, 2020

Checklist

  • Tick to sign-off your agreement to the Developer Certificate of Origin (DCO) 1.1
  • Added tests for code changes or test/build only changes
  • Updated the change log file (CHANGES.md|CHANGELOG.md) or test/build only changes
  • Completed the PR template below:

Description

The issue is described in #468 .
create_query_index does not always supply partitioned which is
always required by the service.

Approach

This PR changes the behavior that so that partitioned is now always
present in the create_query_index requests.

Schema & API Changes

- "No change"

EDIT: Two default False parameters have been changed to None. The users should not notice any difference.

Security and Privacy

  • "No change"

Testing

  • Added new test case

Monitoring and Logging

  • "No change"

This fixes #468

@bessbd bessbd force-pushed the fix-create_query_index-missing-partitioned branch from 56d1a07 to 1a9cd98 Compare May 12, 2020 12:35
Bessenyei Balázs Donát added 3 commits May 12, 2020 14:56
`create_query_index` does not always supply `partitioned` which is
always required by the service.

This commit changes that so that `partitioned` is now always
present in the `create_query_index` requests.

This fixes #468
@bessbd bessbd force-pushed the fix-create_query_index-missing-partitioned branch from 1a9cd98 to 588bf00 Compare May 12, 2020 12:56
@bessbd bessbd marked this pull request as ready for review May 12, 2020 13:24
@@ -47,7 +47,7 @@ class Index(object):
:func:`~cloudant.database.CloudantDatabase.create_query_index`.
"""

def __init__(self, database, design_document_id=None, name=None, partitioned=False, **kwargs):
def __init__(self, database, design_document_id=None, name=None, partitioned=None, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need to update the docs to match the behaviour.

Similarly, to define a partitioned Cloudant Query index you must set the partitioned=True optional.

I think we didn't actually honour this behaviour before - i.e. we didn't write False and the server side default was true in a partitioned database so it wasn't actually a requirement to set partitioned=True (even though I think that was the intention†).

† - IIRC the intention was to provide a stable default value (False) client-side rather than following the server-side approach where the default changed depending on whether the database is partitioned or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs seem correct - as in it looks like it reflects the current behavior.
Would you like me to add that partitioned=False needs to be explicitly set for unpartitioned cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this truth table accurate?

Client-side value Partitioned Database Resulting index is partitioned
None False False
None True True
False False False
False True False
True False 400
True True True

If so then doesn't the second row contradict the docs because you can get a partitioned index without setting partitioned=True in one case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was only considering this from a python-cloudant perspective, where a specified partitioned=False was not passed to the service because of https://github.com/cloudant/python-cloudant/pull/470/files#diff-eeec48d80ce666f16517361d09cf63f1L157 , but that is required according to https://docs.couchdb.org/en/stable/api/database/find.html#post--db-_index , so a "third" boolean state is necessary ( https://github.com/cloudant/python-cloudant/pull/470/files#diff-eeec48d80ce666f16517361d09cf63f1R157 ) the "high impedance" None, because some versions of the service return a 400 for a specified partitioned: https://travis-ci.org/github/cloudant/python-cloudant/jobs/686082038#L426 .

If so then doesn't the second row contradict the docs because you can get a partitioned index without setting partitioned=True in one case?

My understanding as per https://docs.couchdb.org/en/stable/api/database/find.html#post--db-_index is that partitioned always has to be specified in recent versions of CouchDB.

Do you have any specific doc changes in mind? That should help me understand what I'm missing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was trying to say is that your change means that in the case where the database is partitioned and the user does not specify a value for partitioned in python-cloudant the resulting index will still be created as partitioned (because of the server-side default).
The documentation states that:

you must set the partitioned=True

But that "must" does not apply in the case described. I understand the confusion because the code didn't actually work as the doc described before (i.e. your change preserves the existing behaviour for this particular case).

The docs statement:
Similarly, to define a partitioned Cloudant Query index you must set the partitioned=True optional.
needs to change to something like:

To define a partitioned Cloudant Query index you may set the partitioned=True optional, but it is not required as the index will be partitioned by default in a partitioned database. Conversely, you must set the partitioned=False optional if you wish to create a global (non-partitioned) index in a partitioned database.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the lines verbatim in f6c9146 . Is this what you've meant, @ricellis ?

Copy link
Member

@ricellis ricellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 just one suggestion for improving the change entry.

CHANGES.md Outdated
@@ -1,6 +1,7 @@
# UNRELEASED

- [FIXED] Set default value for `partitioned` parameter to false when creating a design document.
- [FIXED] Always set `partitioned` for `create_query_index` requests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be a little confusing for a user because it could imply that we're always setting partitioned=True and nit for a trailing period/full stop.
How about:

- [FIXED] -  Corrected setting of `partitioned` flag for `create_query_index` requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 675de0d .

@bessbd
Copy link
Contributor Author

bessbd commented May 14, 2020

Thank you for the review, @ricellis ! I'm about to merge this once CI passes.

@bessbd bessbd merged commit 14646b7 into master May 14, 2020
@bessbd bessbd deleted the fix-create_query_index-missing-partitioned branch May 14, 2020 11:31
@ricellis ricellis added this to the 2.14.0 milestone Aug 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create_query_index() failing on unpartitioned CouchDB database with message invalid_partitioned_option
2 participants