Skip to content

Unicode check in SA 0.6.1 causes problems for MySQL < 4.0.2 #1826

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Anonymous

See discussion at http://groups.google.com/group/sqlalchemy/browse_thread/thread/5e51d180253cc14b

When first connecting to a database, SA issues a query to see if the DB returns unicode strings for certain data types using a CAST. Unfortunately, CAST was not added to MySQL until v 4.0.2, so SA 0.6.1 is unable to connect to older versions.

The mailing list discussion suggests 3 alternatives:

  1. have cast() do nothing with the MySQL dialect if the MySQL version < 4.0.2 (is there some MySQL-specific syntax that works maybe ?)

  2. have the MySQL dialect not run _check_unicode_returns if the version < 4.0.2

  3. put the unicode checks in a try/except and default the returns to False if something didn't work

I've tested option 1 very briefly, and it seemed to work, but I have not tested extensively. I'm putting this ticket at low priority because I think I'm probably the only person still using such an old version, and I'm not going to have a chance to test further for a week or two at least.

The patch for turning CAST into a noop is:

diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -1187,6 +1187,8 @@

     def visit_cast(self, cast, **kwargs):
         # No cast until 4, no decimals until 5.
+        if self.dialect.server_version_info < (4, 0, 2):
+            return self.process(cast.clause)
         type_ = self.process(cast.typeclause)
         if type_ is None:
             return self.process(cast.clause)

When I next get time to look at this, I'll add a patch for the tests to this ticket.

Thanks,

Simon

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Jun 11, 2010

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

we'll likely put this into 0.6.2.

sqlalchemy-bot

sqlalchemy-bot commented on Jun 11, 2010

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • removed labels: access
  • added labels: mysql
  • changed assignee from "paj" to "jek"
  • set milestone to "0.6.2"
sqlalchemy-bot

sqlalchemy-bot commented on Jun 19, 2010

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

the patch plus a test is in 17073a0. Hoping this fixes the larger issue for the unicode check on connect.

sqlalchemy-bot

sqlalchemy-bot commented on Jun 19, 2010

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
added this to the 0.6.2 milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          Unicode check in SA 0.6.1 causes problems for MySQL < 4.0.2 · Issue #1826 · sqlalchemy/sqlalchemy