Skip to content

Commit

Permalink
fix bug where datatype is read from
Browse files Browse the repository at this point in the history
See sqlc-dev#1460 (comment)

DataType is never filled in so this comparison is buggy. This change mirrors
what the go gen.go does instead.

Deleting a field from proto can be not safe for compat, so we could use
https://developers.google.com/protocol-buffers/docs/proto3#reserved,
but I think these protos are transient so it should be ok.
  • Loading branch information
stephen committed Mar 2, 2022
1 parent ccf980b commit 2cec58a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 94 deletions.
3 changes: 2 additions & 1 deletion internal/codegen/python/gen.go
Expand Up @@ -187,6 +187,7 @@ func makePyType(req *plugin.CodeGenRequest, col *plugin.Column) pyType {
}

func pyInnerType(req *plugin.CodeGenRequest, col *plugin.Column) string {
columnType := sdk.DataType(col.Type)
for _, oride := range req.Settings.Overrides {
if !pyTypeIsSet(oride.PythonType) {
continue
Expand All @@ -195,7 +196,7 @@ func pyInnerType(req *plugin.CodeGenRequest, col *plugin.Column) string {
if oride.Column != "" && sdk.MatchString(oride.ColumnName, col.Name) && sameTable {
return pyTypeString(oride.PythonType)
}
if oride.DbType != "" && oride.DbType == col.DataType && oride.Nullable != (col.NotNull || col.IsArray) {
if oride.DbType != "" && oride.DbType == columnType && oride.Nullable != (col.NotNull || col.IsArray) {
return pyTypeString(oride.PythonType)
}
}
Expand Down
89 changes: 40 additions & 49 deletions internal/plugin/codegen.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 0 additions & 43 deletions internal/plugin/codegen_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion protos/plugin/codegen.proto
Expand Up @@ -158,7 +158,6 @@ message Column
Identifier table = 10;
string table_alias = 11;
Identifier type = 12;
string data_type = 13;
}

message Query
Expand Down

0 comments on commit 2cec58a

Please sign in to comment.