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

Cannot clear an optional string (UUID) #230

Closed
amorenoz opened this issue Oct 1, 2021 · 0 comments · Fixed by #231
Closed

Cannot clear an optional string (UUID) #230

amorenoz opened this issue Oct 1, 2021 · 0 comments · Fixed by #231

Comments

@amorenoz
Copy link
Collaborator

amorenoz commented Oct 1, 2021

Say I have:

type bridgeType struct {
	UUID           string            `ovsdb:"_uuid"`
	Name           string            `ovsdb:"name"`
	IPFIX          *string           `ovsdb:"ipfix"`
}

type ipfixType struct {
	UUID    string   `ovsdb:"_uuid"`
	Targets []string `ovsdb:"targets"`
}

As mentioned in #229 , in order to create an IPFIX row, I need to use Update(), so let's do it:

	ipfix := ipfixType{
		UUID:    namedUUID,
		Targets: []string{"127.0.0.1:6650"},
	}
	insertOp, err := client.Create(&ipfix)
        [...]
	bridge := bridgeType{
		UUID:  uuid,
		IPFIX: &namedUUID,
	}
	updateOps, err := client.Where(&bridge).Update(&bridge, &bridge.IPFIX)
	require.NoError(suite.T(), err)

Now, if I want to delete the IPFIX row, I have two options:

  1. delete the row itself using Delete()
  2. remove the reference to it and let ovsdb-server clean the row for me. I cannot make this one work:

I've tried:

	empty := ""
	bridge.IPFIX = &empty
	updateOps, err = suite.client.Where(&bridge).Update(&bridge, &bridge.IPFIX)

Apart from the code being a bit weird, I get this server-side error:

syntax error: named-uuid string is not a valid <id>

So I also tried

	bridge.IPFIX = nil
	updateOps, err = suite.client.Where(&bridge).Update(&bridge, &bridge.IPFIX)

but I get:

=== RUN   TestOVSIntegrationTestSuite/TestCreateIPFIX                                                                                                                                                                                                                             
    suite.go:63: test panicked: runtime error: invalid memory address or nil pointer dereference                                                                                                                                                                                  
        goroutine 82 [running]:                                                                                                                                                                                                                                                   
        runtime/debug.Stack(0xc000524da8, 0xbe41e0, 0x1044ea0)                                                                           
                /usr/lib/golang/src/runtime/debug/stack.go:24 +0xab                                                                                                                                                                                                               
        github.com/stretchr/testify/suite.failOnPanic(0xc0004c3500)                                                                                                                                                                                                               
                /home/amorenoz/code/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:63 +0x6d                                                                                                                                                                         
        panic(0xbe41e0, 0x1044ea0)                                                                                                                                                                                                                                                
                /usr/lib/golang/src/runtime/panic.go:971 +0x499                                                                                                                                                                                                                   
        github.com/ovn-org/libovsdb/ovsdb.NativeToOvs(0xc000098f00, 0xbae160, 0x0, 0xb8cd01, 0x5, 0x0, 0x0)                                                                                                                                                                       
                /home/amorenoz/code/libovsdb/ovsdb/bindings.go:269 +0x60d                                                                                                                                                                                                         
        github.com/ovn-org/libovsdb/mapper.Mapper.NewRow(0xc0004993e0, 0xc7d6a3, 0x6, 0xba64a0, 0xc00044e360, 0xc00050e4a0, 0x1, 0x1, 0x0, 0x18, ...)                                                                                                                             
                /home/amorenoz/code/libovsdb/mapper/mapper.go:155 +0x63e                                                                                                                                                                                                          
        github.com/ovn-org/libovsdb/client.api.Update(0xc0000a3ae0, 0xd4e110, 0xc0000e2510, 0xba64a0, 0xc00044e360, 0xc00050e4a0, 0x1, 0x1, 0xc00050e4a0, 0xc000508000, ...)                                                                                                      
                /home/amorenoz/code/libovsdb/client/api.go:337 +0x208                                                                                                                                                                                                             
        github.com/ovn-org/libovsdb/test/ovs.(*OVSIntegrationSuite).TestCreateIPFIX(0xc000224900)                                                                                                                                                                                 
                /home/amorenoz/code/libovsdb/test/ovs/ovs_integration_test.go:633 +0xad0                                                 
        reflect.Value.call(0xc0003be360, 0xc0000105a8, 0x13, 0xc7c950, 0x4, 0xc00011de20, 0x1, 0x1, 0xc00018c400, 0xc00018c400, ...)     
                /usr/lib/golang/src/reflect/value.go:476 +0x99c                                                                          
        reflect.Value.Call(0xc0003be360, 0xc0000105a8, 0x13, 0xc00011de20, 0x1, 0x1, 0x26, 0xc00011dc38, 0x48d8b0)                       
                /usr/lib/golang/src/reflect/value.go:337 +0xd9                                                                           
        github.com/stretchr/testify/suite.Run.func1(0xc0004c3500)                                                                        
                /home/amorenoz/code/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:158 +0x392                              
        testing.tRunner(0xc0004c3500, 0xc000408240)                                                                                      
                /usr/lib/golang/src/testing/testing.go:1193 +0x203                                                                       
        created by testing.(*T).Run                                                                                                      
                /usr/lib/golang/src/testing/testing.go:1238 +0x5d8           
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 a pull request may close this issue.

1 participant