You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The rdbms library is imported in _gae.py:
`# -- coding: utf-8 --
try:
from new import classobj
except ImportError:
classobj = type
try:
from google.appengine.ext import db as gae
except ImportError:
gae = None
Key = None
else:
from google.appengine.ext import ndb
from google.appengine.api import namespace_manager, rdbms
from google.appengine.api.datastore_types import Key # for belongs on ID
from google.appengine.ext.ndb.polymodel import PolyModel as NDBPolyModel`
And it is used for the google:sql connection in google.py adpater:
`if gae:
from .._gae import ndb, rdbms, namespace_manager, classobj, NDBPolyModel
from ..helpers.gae import NDBDecimalProperty
class GoogleMigratorMixin(object):
migrator_cls = InDBMigrator
@adapters.register_for("google:sql")
class GoogleSQL(GoogleMigratorMixin, MySQL):
uploads_in_blob = True
REGEX_URI = "^(?P.*)/(?P.+)$"
def _find_work_folder(self):
super(GoogleSQL, self)._find_work_folder()
if os.path.isabs(self.folder) and self.folder.startswith(os.getcwd()):
self.folder = os.path.relpath(self.folder, os.getcwd())
def _initialize_(self):
super(GoogleSQL, self)._initialize_()
self.folder = self.folder or pjoin(
"$HOME",
THREAD_LOCAL._pydal_folder_.split(os.sep + "applications" + os.sep, 1)[1],
)
ruri = self.uri.split("://", 1)[1]
m = re.match(self.REGEX_URI, ruri)
if not m:
raise SyntaxError("Invalid URI string in DAL")
self.driver_args["instance"] = self.credential_decoder(m.group("instance"))
self.dbstring = self.credential_decoder(m.group("db"))
self.createdb = self.adapter_args.get("createdb", True)
if not self.createdb:
self.driver_args["database"] = self.dbstring
def find_driver(self):
self.driver = "google"
def connector(self):
return rdbms.connect(**self.driver_args)
Simply having the library installed will cause an import error:
...[truncated for clarity]...
from pydal import Field
File "/path/to/venv/lib/python3.11/site-packages/pydal/__init__.py", line 3, in <module>
from .base import DAL
File "/path/to/venv/lib/python3.11/site-packages/pydal/base.py", line 168, in <module>
from .objects import Table, Field, Rows, Row, Set
File "/path/to/venv/lib/python3.11/site-packages/pydal/objects.py", line 38, in <module>
from ._gae import Key
File "/path/to/venv/lib/python3.11/site-packages/pydal/_gae.py", line 15, in <module>
from google.appengine.api import namespace_manager, rdbms
ImportError: cannot import name 'rdbms' from 'google.appengine.api' (/path/to/venv/lib/python3.11/site-packages/google/appengine/api/__init__.py)
This happens even when not using a "gae" connection string since _gae.py always executes.
For those encountering the issue I have this (inelegant) workaround (place before importing pydal):
try:
fromgoogle.appengine.apiimportrdbmsexceptImportError:
# Define a "mock" `rdbms` class to serve as a placeholderclassmock_rdbms():
pass# Set the modulefromsysimportmodulesmodules['google.appengine.api.rdbms'] =mock_rdbms# Set _gae.gae to None to ensure that the mock class is never calledfrompydalimport_gae_gae.gae=None
I have to assume that the intersection of people needing the appengine api installed and using pydal is small, but hopefully this can get some eyes on it for a permanent fix.
This warning appears when running in google app engine:
Please remove any imports of google.appengine.api.rdbms. First Generation Cloud SQL instances have been shut down, and rdbms.py will be removed in a future release. See: https://cloud.google.com/sql/docs/mysql/deprecation-notice
The rdbms library is imported in _gae.py:
`# -- coding: utf-8 --
try:
from new import classobj
except ImportError:
classobj = type
try:
from google.appengine.ext import db as gae
except ImportError:
gae = None
Key = None
else:
from google.appengine.ext import ndb
from google.appengine.api import namespace_manager, rdbms
from google.appengine.api.datastore_types import Key # for belongs on ID
from google.appengine.ext.ndb.polymodel import PolyModel as NDBPolyModel`
And it is used for the google:sql connection in google.py adpater:
`if gae:
from .._gae import ndb, rdbms, namespace_manager, classobj, NDBPolyModel
from ..helpers.gae import NDBDecimalProperty
class GoogleMigratorMixin(object):
migrator_cls = InDBMigrator
@adapters.register_for("google:sql")
class GoogleSQL(GoogleMigratorMixin, MySQL):
uploads_in_blob = True
REGEX_URI = "^(?P.*)/(?P.+)$"
`
https://cloud.google.com/appengine/docs/standard/python/refdocs/modules/google/appengine/api/rdbms#connect
The text was updated successfully, but these errors were encountered: