Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DatabaseAdmin: on Duplicate name in Schema, gRPC FailedPrecondition status code is not handled and sent back as None #38

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

Closed
odeke-em opened this issue Mar 16, 2020 · 2 comments
Assignees
Labels
api: spanner Issues related to the googleapis/python-spanner API. 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.

Comments

@odeke-em
Copy link
Contributor

If I have a table that already exists and try to create the same table, this package errors but its error code is None yet its message is Duplicate name in schema: .

Reproduction

from google.cloud import spanner_v1 as spanner

def main():
    db = spanner.Client().instance('django-tests').database('db1')
    lro = db.update_ddl(['CREATE TABLE foo (id INT64) PRIMARY KEY(id)'])

    try:
        result = lro.result()
    except Exception as e:
        print('\033[31mCode: %s gRPC_StatusCode: %s Message: %s\033[00m' % 
                (e.code, e.grpc_status_code, e.message))
        raise e
    else:
        print(result)

if __name__ == '__main__':
    main()

which unfortunately prints out

Code: None gRPC_StatusCode: None Message: Duplicate name in schema: foo.
Traceback (most recent call last):
  File "duplicate_table_v1.py", line 18, in <module>
    main()
  File "duplicate_table_v1.py", line 12, in main
    raise e
  File "duplicate_table_v1.py", line 8, in main
    result = lro.result()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/api_core/future/polling.py", line 127, in result
    raise self._exception
google.api_core.exceptions.GoogleAPICallError: None Duplicate name in schema: foo.

This bug presents an inconsistency in the error handling because we get an error with a None status code and None gRPC status code, yet it has a message.

Comparison with Go

I can confirm that Cloud Spanner actually sends back the status code because the Go result actually has the status code, with this reproduction and by investigation the responses sent by the Spanner server

package main

import (
	"context"

	dbadmin "cloud.google.com/go/spanner/admin/database/apiv1"
	dbspb "google.golang.org/genproto/googleapis/spanner/admin/database/v1"
)

func main() {
	ctx := context.Background()
	adminClient, err := dbadmin.NewDatabaseAdminClient(ctx)
	if err != nil {
		panic(err)
	}
	ddlReq := &dbspb.UpdateDatabaseDdlRequest{
		Database: "projects/orijtech-161805/instances/django-tests/databases/db1",
		Statements: []string{
			"CREATE TABLE foo (id INT64) PRIMARY KEY(id)",
		},
	}
	lro, err := adminClient.UpdateDatabaseDdl(ctx, ddlReq)
	if err != nil {
		panic(err)
	}
	if err := lro.Wait(ctx); err != nil {
		panic(err)
	}
}

and prints out

Sleeping for 947.779411ms
panic: rpc error: code = FailedPrecondition desc = Duplicate name in schema: foo.

goroutine 1 [running]:
main.main()
	/Users/emmanuelodeke/Desktop/spanner-orm-trials/duplicate_table.go:27 +0x1db
exit status 2

Postulation

I think that the result of waiting on the long running operation isn't being properly used to retrieve the status code.

/cc @larkee @skuruppu, and for an FYI @bvandiver @timgraham

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner API. label Mar 16, 2020
odeke-em added a commit to googleapis/python-spanner-django that referenced this issue Mar 16, 2020
spanner-python has a bug due to improper status code extraction
from long running operations as per
googleapis/python-spanner#38

This change adds error translation for update_ddl invocations.

While here, refactored common code for Connection present in both:
* autocommit_off_connection.py
* autocommit_on_connection.py

which makes it easier to add error handling in one place instead
of in 2 places.

Fixes #344
odeke-em added a commit to googleapis/python-spanner-django that referenced this issue Mar 16, 2020
spanner-python has a bug due to improper status code extraction
from long running operations as per
googleapis/python-spanner#38

This change adds error translation for update_ddl invocations.

While here, refactored common code for Connection present in both:
* autocommit_off_connection.py
* autocommit_on_connection.py

which makes it easier to add error handling in one place instead
of in 2 places.

Fixes #344
odeke-em added a commit to googleapis/python-spanner-django that referenced this issue Mar 16, 2020
spanner-python has a bug due to improper status code extraction
from long running operations as per
googleapis/python-spanner#38

This change adds error translation for update_ddl invocations.

While here, refactored common code for Connection present in both:
* autocommit_off_connection.py
* autocommit_on_connection.py

which makes it easier to add error handling in one place instead
of in 2 places.

Fixes #344
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 16, 2020
@odeke-em
Copy link
Contributor Author

The same issue exists when I try to create a new table whose casing is different from a table that exists already e.g. t1 being created, when T1 already exists

google.api_core.exceptions.GoogleAPICallError: None Schema object names differ only in case: T1, t1.

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Mar 21, 2020
@larkee larkee added 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 Mar 22, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Mar 22, 2020
@larkee larkee added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Mar 23, 2020
@larkee
Copy link
Contributor

larkee commented Mar 23, 2020

Thanks for filing this issue!

This issue is due to a bug in another repo (python-api-core). I have made a bug in that repo and am close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner API. 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.
Projects
None yet
Development

No branches or pull requests

3 participants