GithubHelp home page GithubHelp logo

Comments (3)

dbussink avatar dbussink commented on July 2, 2024 1

I think that we should be using protojson.Unmarshal which supports both the json names and the proto names.

This seems wrong. json2 calls protojson if the given target is a proto.Message and it adds more human readable / better error messages. We should be using json2 really and I'm very confused why it doesn't work then. I think we should understand that first before it's changed to protojson (and we might have bugs like this in more places if there's some way json2 doesn't work as expected).

if pb, ok := v.(proto.Message); ok {
opts := protojson.UnmarshalOptions{DiscardUnknown: true}
return annotate(data, opts.Unmarshal(data, pb))
}

from vitess.

mattlord avatar mattlord commented on July 2, 2024

The problem is here: https://github.com/vitessio/vitess/blob/main/go/cmd/vtctldclient/command/routing_rules.go#L84-L87

I think that we should be using protojson.Unmarshal which supports both the json names and the proto names.

Test case that fails on main:

git checkout main && make build
pushd examples/local

./101_initial_cluster.sh

vtctldclient ApplyRoutingRules --rules '{                                                                                                                        
    "rules": [
        {
            "fromTable": "sbtest1",
            "toTables": [
                "sbtest.sbtest1"
            ]
        }
    ]
}'

That same test case works as expected after this patch/fix:

diff --git a/go/cmd/vtctldclient/command/routing_rules.go b/go/cmd/vtctldclient/command/routing_rules.go
index 0ffee0c2c2..119c8dbb41 100644
--- a/go/cmd/vtctldclient/command/routing_rules.go
+++ b/go/cmd/vtctldclient/command/routing_rules.go
@@ -23,9 +23,9 @@ import (
        "strings"

        "github.com/spf13/cobra"
+       "google.golang.org/protobuf/encoding/protojson"

        "vitess.io/vitess/go/cmd/vtctldclient/cli"
-       "vitess.io/vitess/go/json2"

        vschemapb "vitess.io/vitess/go/vt/proto/vschema"
        vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
@@ -82,7 +82,7 @@ func commandApplyRoutingRules(cmd *cobra.Command, args []string) error {
        }

        rr := &vschemapb.RoutingRules{}
-       if err := json2.Unmarshal(rulesBytes, &rr); err != nil {
+       if err := protojson.Unmarshal(rulesBytes, rr); err != nil {
                return err
        }

I'm not sure if that's the right/best ultimate fix, but it points to the problem space.

from vitess.

rohit-nayak-ps avatar rohit-nayak-ps commented on July 2, 2024

fixed via #16096

from vitess.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.