[go: nahoru, domu]

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

datastore: ErrFieldMismatch on sub fields clears out top level array field #5074

Open
evanwht opened this issue Nov 3, 2021 · 3 comments
Open
Assignees
Labels
api: datastore Issues related to the Datastore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@evanwht
Copy link
evanwht commented Nov 3, 2021

Client

datastore

Environment

MacOS

Go Environment

go1.17.2 darwin/amd64
cloud.google.com/do/datastore v.1.16.0

Code

type (
	ComplexObject struct {
		Field1 string
		Field2 []ComplexSubObject
	}
	ComplexSubObject struct {
		SubField1 string
		SubField2 struct {
			SubSubField1 string
			SubSubField2 string
		}
	}

	SimpleObject struct {
		Field1 string
		Field2 []SimpleSubObject
	}
	SimpleSubObject struct {
		SubField1 string
		SubField2 struct {
			SubSubField1 string
		}
	}
)

func TestFieldMismatchLoading() {
	ctx := context.Background()
	c, err := datastore.NewClient(ctx, "my-project")
	if err != nil {
		panic(err)
	}

	o := ComplexObject{
		Field1: "field-1",
		Field2: []ComplexSubObject{{
			SubField1: "sub-field-1",
			SubField2: struct {
				SubSubField1 string
				SubSubField2 string
			}{
				SubSubField1: "sub-sub-field-1",
				SubSubField2: "sub-sub-field-2",
			},
		}},
	}
	fmt.Printf("%+v\n", o)
	key, err := c.Put(ctx, datastore.IncompleteKey("test", nil), &o)
	if err != nil {
		panic(err)
	}

	var s SimpleObject
	err = c.Get(ctx, key, &s)
	if err != nil {
		if _, ok := err.(*datastore.ErrFieldMismatch); !ok {
			panic(err)
		}
	}
	fmt.Printf("%+v\n", s)
}

Expected behavior

Field2 of the entity should load with one entry that contains an A field and a B that only contains the one field it knows about. The documentation for loading suggests that as many fields are filled out as possible and an error is returned alerting the user that there was a field mismatch.

Actual behavior

Field2 is returned as an empty array.

Additional context

If you change Field2 to not be an array, the sub object loads all possible fields that it can.

@evanwht evanwht added the triage me I really want to be triaged. label Nov 3, 2021
@product-auto-label product-auto-label bot added the api: datastore Issues related to the Datastore API. label Nov 3, 2021
@crwilcox crwilcox assigned dmahugh and unassigned crwilcox Nov 3, 2021
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Nov 8, 2021
@meredithslota meredithslota added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. 🚨 This issue needs some love. labels Nov 15, 2021
@evanwht
Copy link
Author
evanwht commented Jan 5, 2022

@dmahugh any updates on when this will be looked at?

@telpirion telpirion assigned telpirion and unassigned dmahugh Jan 18, 2022
@telpirion
Copy link
Contributor
telpirion commented Mar 10, 2022

@evanwht The Datastore package is now at v1.6.0. Would you please check your library version and let me know what you're using?

Also you mention the "documentation for loading": would you please provide a link to the documentation where you found that statement?

Thank you!

@evanwht
Copy link
Author
evanwht commented Mar 23, 2022

@telpirion I am using v1.6.0 in my test cases.

The exact comments I found are here

// We don't return early, as we try to load as many properties as possible.
// It is valid to load an entity into a struct that cannot fully represent it.
// That case returns an error, but the caller is free to ignore it.

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label May 2, 2022
@telpirion telpirion added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. 🚨 This issue needs some love. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Sep 23, 2022
@telpirion telpirion assigned triplequark and unassigned telpirion Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

7 participants