René's URL Explorer Experiment


Title: Auto-increment ID from MySQL is not populated in model instance when Spanner is the default DB · Issue #15930 · googleapis/google-cloud-python · GitHub

Open Graph Title: Auto-increment ID from MySQL is not populated in model instance when Spanner is the default DB · Issue #15930 · googleapis/google-cloud-python

X Title: Auto-increment ID from MySQL is not populated in model instance when Spanner is the default DB · Issue #15930 · googleapis/google-cloud-python

Description: Summary When using a multi-database setup with django-google-spanner as the default database and Cloud SQL (MySQL) as a secondary database, the auto-incremented ID from MySQL is not being populated back into the model instance after savi...

Open Graph Description: Summary When using a multi-database setup with django-google-spanner as the default database and Cloud SQL (MySQL) as a secondary database, the auto-incremented ID from MySQL is not being populated...

X Description: Summary When using a multi-database setup with django-google-spanner as the default database and Cloud SQL (MySQL) as a secondary database, the auto-incremented ID from MySQL is not being populated...

Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/15930

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Auto-increment ID from MySQL is not populated in model instance when Spanner is the default DB","articleBody":"### Summary\n\nWhen using a multi-database setup with `django-google-spanner` as the `default` database and Cloud SQL (MySQL) as a secondary database, the auto-incremented ID from MySQL is not being populated back into the model instance after saving.\n\n### Environment\n\n* **django-google-spanner version:** 4.0.1 (also tested with 4.0.2)\n* **Django version:** 4.2\n* **Database Backend (Default):** `django_spanner`\n* **Database Backend (Secondary):** `mysql.connector.django`\n\n### Problem Description\n\nWe have a multi-database configuration as follows:\n\n**[1] settings.py**\n```python\nDATABASES = {\n    'default': {\n        'ENGINE': 'django_spanner',\n        'PROJECT': GCP_PROJECT_ID,\n        'INSTANCE': SPANNER_INSTANCE,\n        'NAME': SPANNER_DATABASE,\n    },\n    'cloudsql': {\n        'ENGINE': 'mysql.connector.django',\n        'NAME': SQL_DATABASE,\n        'USER': USER,\n        'PASSWORD': PASSWORD,\n        'HOST': HOST,\n        'OPTIONS': {'charset': 'utf8mb4', 'collation': 'utf8mb4_bin'},\n    }\n}\n```\n\nWe have a model that is configured to use the cloudsql (MySQL) database. The primary key is defined with BigAutoField.\n\n[2] models.py\n\n```python\nclass DeviceMngModel(models.Model):\n    # This model is routed to the 'cloudsql' database.\n    device_mng_id = models.BigAutoField(primary_key=True)\n    # ... other fields\n```\n\nScenario 1: With django-google-spanner==4.0.1 (Default settings)\n\nWhen we create a new record for this model, the device_mng_id is saved to the MySQL table as a very large random integer (likely a 64-bit random number), instead of a standard auto-incremented value.\n\nScenario 2: With django-google-spanner==4.0.2 and a setting change\n\nBased on the library's features, we tried upgrading to 4.0.2 and adding 'RANDOM_ID_GENERATION_ENABLED': 'false' to the default database configuration.\n```\n# settings.py addition\n'default': {\n    'ENGINE': 'django_spanner',\n    'PROJECT': GCP_PROJECT_ID,\n    'INSTANCE': SPANNER_INSTANCE,\n    'NAME': SPANNER_DATABASE,\n    'RANDOM_ID_GENERATION_ENABLED': 'false',\n},\n```\nWith this change, the record in the MySQL table is correctly saved with a proper auto-incremented ID (e.g., 1, 2, 3...).\n\nHowever, the ID is not returned to the Django model instance after the save() method is called. This means we cannot access the newly created ID from the serializer or the model instance.\n\n[3] Code flow\n\n```python\n\nserializer = self.get_serializer(data=data)\nserializer.save()\n# After save(), the ID is not available here:\nprint(serializer.data['device_mng_id'])\n```\n\nExpected Behavior\nAfter serializer.save() is called, the auto-generated device_mng_id from the MySQL database should be populated in the model instance (instance.device_mng_id) and be available in serializer.data.\n\nActual Behavior\nWith 'RANDOM_ID_GENERATION_ENABLED': 'false', the device_mng_id is None on the model instance after saving, and the ID field is absent from serializer.data.\n\nIt seems that the `django-google-spanner` backend, being the default, might be interfering with the mechanism Django uses to fetch the last inserted ID from non-default MySQL databases.\n\nCould you please advise on a possible solution or workaround for this issue? Thank you.","author":{"url":"https://github.com/miyamoto-kei","@type":"Person","name":"miyamoto-kei"},"datePublished":"2025-07-24T00:03:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/15930/google-cloud-python/issues/15930"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:3efaead5-6fd7-6bca-3237-820dd1d41b14
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEC46:3618EF:52BBEC:6E727F:6A629BB5
html-safe-noncee4fb4665f42557e186c88a436b6b28295e6126ab3b064d6ea5306ed15df6a40b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzQ2OjM2MThFRjo1MkJCRUM6NkU3MjdGOjZBNjI5QkI1IiwidmlzaXRvcl9pZCI6IjExMTk1MjAwMjY3NjcwMzk0MTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacec6b6fa50f66a075c91f5e0ef86615c237fe7146c2b2f40356c589d58433b220
hovercard-subject-tagissue:4011556720
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-cloud-python/15930/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ba14680700aa92fa3bb19e589ca2f910c09bfd72815bc5c212e9ac5613a713a0/googleapis/google-cloud-python/issues/15930
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ba14680700aa92fa3bb19e589ca2f910c09bfd72815bc5c212e9ac5613a713a0/googleapis/google-cloud-python/issues/15930
og:image:altSummary When using a multi-database setup with django-google-spanner as the default database and Cloud SQL (MySQL) as a secondary database, the auto-incremented ID from MySQL is not being populated...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemiyamoto-kei
hostnamegithub.com
expected-hostnamegithub.com
Nonea6443033349a18134b517627f043d4a59a5110337b879810c7229c2c7e28eda0
turbo-cache-controlno-preview
go-importgithub.com/googleapis/google-cloud-python git https://github.com/googleapis/google-cloud-python.git
octolytics-dimension-user_id16785467
octolytics-dimension-user_logingoogleapis
octolytics-dimension-repository_id16316451
octolytics-dimension-repository_nwogoogleapis/google-cloud-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id16316451
octolytics-dimension-repository_network_root_nwogoogleapis/google-cloud-python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
released6c6cacbe32d3ddfd1796fbd1a39b8fb47b87daf
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/googleapis/google-cloud-python/issues/15930#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fgoogle-cloud-python%2Fissues%2F15930
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fgoogle-cloud-python%2Fissues%2F15930
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=googleapis%2Fgoogle-cloud-python
Reloadhttps://github.com/googleapis/google-cloud-python/issues/15930
Reloadhttps://github.com/googleapis/google-cloud-python/issues/15930
Reloadhttps://github.com/googleapis/google-cloud-python/issues/15930
Please reload this pagehttps://github.com/googleapis/google-cloud-python/issues/15930
googleapis https://github.com/googleapis
google-cloud-pythonhttps://github.com/googleapis/google-cloud-python
Notifications https://github.com/login?return_to=%2Fgoogleapis%2Fgoogle-cloud-python
Fork 1.7k https://github.com/login?return_to=%2Fgoogleapis%2Fgoogle-cloud-python
Star 5.4k https://github.com/login?return_to=%2Fgoogleapis%2Fgoogle-cloud-python
Code https://github.com/googleapis/google-cloud-python
Issues 494 https://github.com/googleapis/google-cloud-python/issues
Pull requests 146 https://github.com/googleapis/google-cloud-python/pulls
Discussions https://github.com/googleapis/google-cloud-python/discussions
Actions https://github.com/googleapis/google-cloud-python/actions
Projects https://github.com/googleapis/google-cloud-python/projects
Security and quality 0 https://github.com/googleapis/google-cloud-python/security
Insights https://github.com/googleapis/google-cloud-python/pulse
Code https://github.com/googleapis/google-cloud-python
Issues https://github.com/googleapis/google-cloud-python/issues
Pull requests https://github.com/googleapis/google-cloud-python/pulls
Discussions https://github.com/googleapis/google-cloud-python/discussions
Actions https://github.com/googleapis/google-cloud-python/actions
Projects https://github.com/googleapis/google-cloud-python/projects
Security and quality https://github.com/googleapis/google-cloud-python/security
Insights https://github.com/googleapis/google-cloud-python/pulse
#16111https://github.com/googleapis/google-cloud-python/pull/16111
Auto-increment ID from MySQL is not populated in model instance when Spanner is the default DBhttps://github.com/googleapis/google-cloud-python/issues/15930#top
#16111https://github.com/googleapis/google-cloud-python/pull/16111
api: spannerIssues related to the Spanner API.https://github.com/googleapis/google-cloud-python/issues?q=state%3Aopen%20label%3A%22api%3A%20spanner%22
priority: p3Desirable enhancement or fix. May not be included in next release.https://github.com/googleapis/google-cloud-python/issues?q=state%3Aopen%20label%3A%22priority%3A%20p3%22
type: questionRequest for information or clarification. Not an issue.https://github.com/googleapis/google-cloud-python/issues?q=state%3Aopen%20label%3A%22type%3A%20question%22
https://github.com/miyamoto-kei
miyamoto-keihttps://github.com/miyamoto-kei
on Jul 24, 2025https://github.com/googleapis/google-cloud-python/issues/15930#issue-4011556720
api: spannerIssues related to the Spanner API.https://github.com/googleapis/google-cloud-python/issues?q=state%3Aopen%20label%3A%22api%3A%20spanner%22
priority: p3Desirable enhancement or fix. May not be included in next release.https://github.com/googleapis/google-cloud-python/issues?q=state%3Aopen%20label%3A%22priority%3A%20p3%22
type: questionRequest for information or clarification. Not an issue.https://github.com/googleapis/google-cloud-python/issues?q=state%3Aopen%20label%3A%22type%3A%20question%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.