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

Add cycle detection when inserting quads from structs #731

Closed
phyrwork opened this issue Aug 4, 2018 · 0 comments
Closed

Add cycle detection when inserting quads from structs #731

phyrwork opened this issue Aug 4, 2018 · 0 comments
Assignees
Milestone

Comments

@phyrwork
Copy link
Contributor

phyrwork commented Aug 4, 2018

Description

Cayley gets stuck in a recursive loop when trying to insert quads from a struct that (eventually) points to itself

Steps to reproduce the issue:

e.g. (based on one of the examples)

type Person struct {
	// dummy field to enforce all object to have a <id> <rdf:type> <ex:Person> relation
	// means nothing for Go itself
	rdfType   struct{} `quad:"@type > ex:Person"`
	//ID        quad.IRI `json:"@id"`     // tag @id is a special one - graph node value will be stored in this field
	Name      string   `json:"ex:name"` // field name (predicate) may be written as json field name
	Age       int      `quad:"ex:age"`  // or in a quad tag
	Relatives []*Person `quad:"ex:relative"`
}

bob := Person{
	//ID:   quad.IRI("ex:bob").Full().Short(),
	Name: "Bob", Age: 32,
}
jane := Person{
	//ID:   quad.IRI("ex:bob").Full().Short(),
	Name: "Jane", Age: 32,
}

bob.Relatives = []*Person{
	&jane,
}
jane.Relatives = []*Person{
	&bob,
}

fmt.Printf("saving: %+v\n", bob)
id, err := config.WriteAsQuads(writer, bob)
checkErr(err)
fmt.Println("id for object:", id) // should be equal

Received results:

=== RUN   Test_SchemaExample
saving: {rdfType:{} Name:Bob Age:32 Relatives:[0xc420078720]}
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

Expected results:

Nodes 'bob' and 'jane' added to graph without error

Output of cayley version or commit hash:

945c4253f890b0048a31da7c4a8a7c06625457c7

Environment details:

Backend database: MemoryGraph

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

No branches or pull requests

2 participants