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

Missing partition key on header #75

Closed
wikes82 opened this issue Jan 9, 2019 · 8 comments
Closed

Missing partition key on header #75

wikes82 opened this issue Jan 9, 2019 · 8 comments
Assignees

Comments

@wikes82
Copy link

wikes82 commented Jan 9, 2019

Bug Information

when calling AzureData.createDocument() to collection with partition key, it produce error : The partition key supplied in x-ms-partitionkey header has fewer components than defined in the the collection.
REST request header missing x-ms-documentdb-partitionkey

Steps to Reproduce

call AzureData.createDocument() to collection with partition key.

Expected Behavior

Actual Behavior

Code snippet

Screenshots

@NateRickard
Copy link
Member

NateRickard commented Feb 5, 2019

It looks like this change in the portal:

screenshot 2019-02-05 16 04 14

...is causing all collections created via the portal to require a partition key. Currently this SDK has no method of passing a partition key in the header, leading to the error.

This SDK will be updated to allow for the partition key. In the meantime, a workaround is to create the collection programmatically via the SDK, which does not require a partition key to be set.

@SogoGolf
Copy link

SogoGolf commented Feb 7, 2019

thanks for confirming this @NateRickard looking forward to the update

@NateRickard
Copy link
Member

@SogoGolf should be fixed in PR #86/v0.2.0

@SogoGolf
Copy link

hi @NateRickard just tested this and I'm still seeing same error. i checked i had updated to 0.2.0 perhaps i missed something else. here's the details:

the database test and collection testcollection were created in the portal UI.

image

image

implementation 'com.azure.android:azuredata:0.2.0'

update worked fine/build ok.

doc class:

class ClubDocument(id: String? = null) : Document(id) {
    var name: String = ""
    var type: String = ""
}

test code block:

val document = ClubDocument()
document.name = "NEW CLUB ${(0..100).random()}"
document.type = "abc"

AzureData.createDocument (document, "testcollection", "test") {
    // created document = it.resource
    if (it.response != null && it.response?.isSuccessful!!) {
        lastAddedId = it.resource?.id!!
        runOnUiThread {
            textView.text = "success creating a new club. ${it.jsonData}"
        }
    } else {
        Log.i("AZURE", "ERROR: create document failed. ${it.jsonData}")
        runOnUiThread {
            textView.text = "ERROR: ${it.jsonData}"
        }
    }
}

error message:

create document failed. {"code":"BadRequest","message":"Message: {\"Errors\":[\"The partition key supplied in x-ms-partitionkey header has fewer components than defined in the the collection.\"]}

@NateRickard
Copy link
Member

@SogoGolf mark the property you're using as the partition key with the @PartitionKey annotation, e.g.:

@PartitionKey
    var testKey = "MyPartitionKey"

Docs are lagging behind as we iterate on this, but you can look at the tests which should give you some insight.

@radoye
Copy link

radoye commented Apr 5, 2019

I can't seem to find an example for Java. I tried something like the snipped below, but it's failing. Any hints/pointers? Thanks!

    static class SampleDocument extends Document {
        String guid;
        @PartitionKey // <== fails here with "@PartitionKey not applicable to field"
        String guid_date;
        JSONObject payload;

      SampleDocument(...) {}
}

@NateRickard
Copy link
Member

@radoye thanks for the feedback. I've updated the attribute to work on fields as well. Let me know if this fixes the issue for you. Released in v0.2.5.

@radoye
Copy link

radoye commented Apr 5, 2019

@NateRickard thanks for the fix! I can confirm that it works in 0.2.5.

azure-sdk pushed a commit to azure-sdk/azure-sdk-for-android that referenced this issue Sep 16, 2020
azure-sdk pushed a commit that referenced this issue Sep 26, 2020
* Added multi-stage definition scaffolding.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants