Skip to content

clean up mysql server version comaprison to use an int field #4189

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Nicolas Bur (@nbur)

Traceback (most recent call last):
print(db.table_names())
File "/home/nbur/.local/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 2139, in table_names
return self.dialect.get_table_names(conn, schema)
File "", line 2, in get_table_names
File "/home/nbur/.local/lib/python3.5/site-packages/sqlalchemy/engine/reflection.py", line 42, in cache
return fn(self, con, *args, **kw)
File "/home/nbur/.local/lib/python3.5/site-packages/sqlalchemy/dialects/mysql/base.py", line 1950, in get_table_names
if self.server_version_info < (5, 0, 2):
TypeError: unorderable types: str() < int()

As written in this log server_version_info doesn't return a tuple of three int
adding

print(self.server_version_info)

line 1950 in File "/home/nbur/.local/lib/python3.5/site-packages/sqlalchemy/dialects/mysql/base.py"
displays (5, 0, '51a', '24+lenny5') which clearly can't be compared with (5, 0, 2)…

I mention there is no problem changing and running my script with python 2.7

SQLAlchemy-1.2.2

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Feb 16, 2018

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

server_version_info() doesn't have a bug here, we need those tokens to be what they are.

the bug here is that you're oddly enough using exactly a 5.0 version that is for some reason sticking a string into the third token. so this is a very unexpected and buggy version string your DB is reporting which we'd have to work around.

sqlalchemy-bot

sqlalchemy-bot commented on Feb 16, 2018

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed title from "server_version_info doesn't return tuple of int to" to "anticipate legacy MySQL version info with strings "
sqlalchemy-bot

sqlalchemy-bot commented on Feb 17, 2018

@sqlalchemy-bot
CollaboratorAuthor

Nicolas Bur (@nbur) wrote:

Therefore I'm going to use python 2.7…
Thank you very much

sqlalchemy-bot

sqlalchemy-bot commented on Feb 17, 2018

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

Ok should have this fixed for next release though

sqlalchemy-bot

sqlalchemy-bot commented on Feb 17, 2018

@sqlalchemy-bot
CollaboratorAuthor

Nicolas Bur (@nbur) wrote:

Great. Glad to have pointed this out :)

sqlalchemy-bot

sqlalchemy-bot commented on Feb 21, 2018

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed milestone from "1.2" to "1.2.x"
added this to the 1.2.x milestone on Nov 27, 2018
zzzeek

zzzeek commented on Dec 22, 2018

@zzzeek
Member

OK so looking at other dialects, psycopg2, pymssql, cx_oracle, all of these take server version info and turn into ints for all tokens, non ints are discarded. this is what we should do here. slight doubt this doesn't break anything but I still think we should do it for 1.2.x.

added
easya one / two liner type of thing that anyone can do in short order. also see "fairly easy"
on Dec 22, 2018
blha303

blha303 commented on Jan 2, 2019

@blha303

I encountered the above bug today connecting to a legacy MySQL server with SQLAlchemy 1.2.15 (via records):

(Pdb) list
1966                return self.server_version_info
1967
1968        @property
1969        def _supports_cast(self):
1970            return self.server_version_info is None or \
1971 ->             self.server_version_info >= (4, 0, 2)
1972
1973        @reflection.cache
1974        def get_schema_names(self, connection, **kw):
1975            rp = connection.execute("SHOW schemas")
1976            return [r[0] for r in rp]
(Pdb) p self.server_version_info
(4, 0, '24_Debian', '10sarge2', 'log')

Is there an estimated time for fixing this? Thanks.

zzzeek

zzzeek commented on Jan 2, 2019

@zzzeek
Member

@blha303 it's tagged "easy" so we usually wait for contributors to pick these up unless the issue is truly urgent. code should be made to remove non-integer tokens, so code at https://github.com/sqlalchemy/sqlalchemy/blob/master/lib/sqlalchemy/dialects/mysql/base.py#L1843 needs to look more like https://github.com/sqlalchemy/sqlalchemy/blob/master/lib/sqlalchemy/dialects/postgresql/base.py#L2446.

removed this from the 1.2.x milestone on May 18, 2019

11 remaining items

Loading
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

    bugSomething isn't workingmysql

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zzzeek@blha303@sqla-tester@sqlalchemy-bot

        Issue actions

          clean up mysql server version comaprison to use an int field · Issue #4189 · sqlalchemy/sqlalchemy