Skip to content
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

Deprecation imports google.appengine.api.rdbms in _gae and google adapter #677

Open
jparga opened this issue Dec 29, 2021 · 1 comment
Open

Comments

@jparga
Copy link

jparga commented Dec 29, 2021

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.+)$"

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)

`

https://cloud.google.com/appengine/docs/standard/python/refdocs/modules/google/appengine/api/rdbms#connect

@thedeltaflyer
Copy link

google.appengine.api.rdbms has now been removed from the Python 3 appengine-python-standard library

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:
    from google.appengine.api import rdbms
except ImportError:
    # Define a "mock" `rdbms` class to serve as a placeholder
    class mock_rdbms():
        pass
    # Set the module
    from sys import modules
    modules['google.appengine.api.rdbms'] = mock_rdbms
    # Set _gae.gae to None to ensure that the mock class is never called
    from pydal import _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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants