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

Build out index tags tests a bit more #319

Merged
merged 4 commits into from
Jan 7, 2025
Merged

Build out index tags tests a bit more #319

merged 4 commits into from
Jan 7, 2025

Conversation

aulorbe
Copy link
Collaborator

@aulorbe aulorbe commented Dec 23, 2024

Problem

I just wanted to ensure that adding, deleting, and updating index tags on the same index gives us the results we expect, so added some integration tests.

Test Plan

CI passes

Copy link
Member

@iamannamai iamannamai left a comment

Choose a reason for hiding this comment

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

I don't really know enough about the expected behavior and that's really not the point of this PR, but love that the test just lets me asks these questions! If the behaviors are all as expected, good to go!

});

await pinecone.configureIndex(serverlessIndexName, {
tags: { project: '' },
});
const description2 = await pinecone.describeIndex(serverlessIndexName);
expect(description2.tags).toBeUndefined();
if (description2.tags != null) {
expect(description2.tags['project']).toBeUndefined();
Copy link
Member

Choose a reason for hiding this comment

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

This is interesting. I'm sure this has already been discussed, but I'd expect to have to explicitly pass null for this to happen and for empty strings to be the case, which is how a few other SDKs we use would do it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the tag itself (the key value) is still present, but the value can be an empty string. If it's an empty string, then it's undefined. Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

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

This is definitely more on the implementation side and agnostic to the SDK, but if I understand correctly that json responses don't really encode undefined, ie. the key is just omitted altogether, providing project: '' in this case would remove the key altogether?

so i'd expect something like

input: `{ "project": null }`, output: `{}`
input: `{ "project": "" }`, output: `{ "project": "" }`

whereas this test tells me

input: `{ "project": "" }`, output: `{ }`

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well, so ' ' removes the key, but the user can't pass null because of type safety in typescript (their IDE will tell them that the passed value in a tag must be a string)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(Same thing happpens here when you sub undefined for null:)

Screenshot 2025-01-07 at 12 52 35 PM

});

await pinecone.configureIndex(serverlessIndexName, {
tags: { project: '' },
});
const description2 = await pinecone.describeIndex(serverlessIndexName);
expect(description2.tags).toBeUndefined();
if (description2.tags != null) {
Copy link
Member

Choose a reason for hiding this comment

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

If undefined != null, does this block still run?

Separately, are tags always returned, even if they're empty? I guess that would be my expectation as a user of the SDK.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Question 1: undefined does equal null.

Question2 : Yes!

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, so the conflation of null and undefined are intentional here because tags should always be {} regardless of whether they've been added to the response or not? That would make sense to me!

Copy link
Member

@iamannamai iamannamai left a comment

Choose a reason for hiding this comment

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

ty for addressing the comments!

});

await pinecone.configureIndex(serverlessIndexName, {
tags: { project: '' },
});
const description2 = await pinecone.describeIndex(serverlessIndexName);
expect(description2.tags).toBeUndefined();
if (description2.tags != null) {
expect(description2.tags['project']).toBeUndefined();
Copy link
Member

Choose a reason for hiding this comment

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

This is definitely more on the implementation side and agnostic to the SDK, but if I understand correctly that json responses don't really encode undefined, ie. the key is just omitted altogether, providing project: '' in this case would remove the key altogether?

so i'd expect something like

input: `{ "project": null }`, output: `{}`
input: `{ "project": "" }`, output: `{ "project": "" }`

whereas this test tells me

input: `{ "project": "" }`, output: `{ }`

});

await pinecone.configureIndex(serverlessIndexName, {
tags: { project: '' },
});
const description2 = await pinecone.describeIndex(serverlessIndexName);
expect(description2.tags).toBeUndefined();
if (description2.tags != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, so the conflation of null and undefined are intentional here because tags should always be {} regardless of whether they've been added to the response or not? That would make sense to me!

@aulorbe aulorbe merged commit 0d0a220 into main Jan 7, 2025
32 checks passed
@aulorbe aulorbe deleted the index-tag-tests branch January 7, 2025 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants