Title: Error in the Cloud Function MySQL example · Issue #2127 · GoogleCloudPlatform/python-docs-samples · GitHub
Open Graph Title: Error in the Cloud Function MySQL example · Issue #2127 · GoogleCloudPlatform/python-docs-samples
X Title: Error in the Cloud Function MySQL example · Issue #2127 · GoogleCloudPlatform/python-docs-samples
Description: In which file did you encounter the issue? master/functions/sql/mysql_sample.py Describe the issue Hi i think i found an issue in the mysql sample for cloud functions, specially on the connection creation: if not mysql_conn: try: mysql_c...
Open Graph Description: In which file did you encounter the issue? master/functions/sql/mysql_sample.py Describe the issue Hi i think i found an issue in the mysql sample for cloud functions, specially on the connection c...
X Description: In which file did you encounter the issue? master/functions/sql/mysql_sample.py Describe the issue Hi i think i found an issue in the mysql sample for cloud functions, specially on the connection c...
Opengraph URL: https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2127
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Error in the Cloud Function MySQL example","articleBody":"## In which file did you encounter the issue?\r\n\r\n_master/functions/sql/mysql_sample.py_\r\n\r\n## Describe the issue\r\nHi i think i found an issue in the mysql sample for cloud functions, specially on the connection creation:\r\n\r\n```\r\nif not mysql_conn:\r\n try:\r\n mysql_conn = pymysql.connect(**mysql_config)\r\n except OperationalError:\r\n # If production settings fail, use local development ones\r\n mysql_config['unix_socket'] = f'/cloudsql/{CONNECTION_NAME}'\r\n mysql_conn = pymysql.connect(**mysql_config)\r\n```\r\n\r\nOn the try side, it will try to connect to the database using the mysql_config dict, but it does not have neither a **host** nor **unix_socket** key:\r\n\r\n```\r\nmysql_config = {\r\n 'user': DB_USER,\r\n 'password': DB_PASSWORD,\r\n 'db': DB_NAME,\r\n 'charset': 'utf8mb4',\r\n 'cursorclass': pymysql.cursors.DictCursor,\r\n 'autocommit': True\r\n}\r\n```\r\nSo that line will most likely fail, on the except side it looks more correct, this adds the unix_socket key with the connection name, so the connection will most likely work. Even the comment on the _except_ part looks misplaced.\r\n\r\n`# If production settings fail, use local development ones`\r\n\r\nI think the except part needs to be on the try part, and the except needs to have the _localhost_ instead. As the postgresql example file (_master/functions/sql/postgres_sample.py_)\r\n\r\nIf I'm wrong please let me know, sorry for the inconvenience.\r\nThanks in advance!","author":{"url":"https://github.com/alejandrombc","@type":"Person","name":"alejandrombc"},"datePublished":"2019-04-29T19:08:54Z","url":"https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2127"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3e005abd-884f-3401-e725-06b861707b4e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B282:EBFE7:28D06E:3702C3:6AFE1A99 |
| html-safe-nonce | d3512efa7d6ee642b7197e52cfde57b542588e3717b13a45548b6fa198c24d50 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjgyOkVCRkU3OjI4RDA2RTozNzAyQzM6NkFGRTFBOTkiLCJ2aXNpdG9yX2lkIjoiMzI1NDczOTE2MjcxMDczOTQ2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6c1c47fc320c0500193da5cee79f2484a5951dc721fd75d1cfd13c582b9a4f33 |
| hovercard-subject-tag | issue:438463087 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/GoogleCloudPlatform/python-docs-samples/2127/issue_layout |
| twitter:image | https://opengraph.githubassets.com/252f61637353b9970ff4f1a76d148354423a7b83a3b55f6c835bc00940d0b297/GoogleCloudPlatform/python-docs-samples/issues/2127 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/252f61637353b9970ff4f1a76d148354423a7b83a3b55f6c835bc00940d0b297/GoogleCloudPlatform/python-docs-samples/issues/2127 |
| og:image:alt | In which file did you encounter the issue? master/functions/sql/mysql_sample.py Describe the issue Hi i think i found an issue in the mysql sample for cloud functions, specially on the connection c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alejandrombc |
| hostname | github.com |
| expected-hostname | github.com |
| None | d0525ab1464526bf4532a5551aa348cf100dff75ef808a96fc67a08b1d946aa9 |
| turbo-cache-control | no-preview |
| go-import | github.com/GoogleCloudPlatform/python-docs-samples git https://github.com/GoogleCloudPlatform/python-docs-samples.git |
| octolytics-dimension-user_id | 2810941 |
| octolytics-dimension-user_login | GoogleCloudPlatform |
| octolytics-dimension-repository_id | 35065876 |
| octolytics-dimension-repository_nwo | GoogleCloudPlatform/python-docs-samples |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 35065876 |
| octolytics-dimension-repository_network_root_nwo | GoogleCloudPlatform/python-docs-samples |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fef3993a71fa20f7be8e167132fbf9619bc66e12 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width