Skip to content

Commit

Permalink
Merge pull request #561 from davidism/sti-unset-table
Browse files Browse the repository at this point in the history
don't mask parent table on single-table inheritance
  • Loading branch information
davidism authored Oct 11, 2017
2 parents be45a9b + c52abbd commit df7903e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ Changelog
=========


Version 2.3.2
-------------

Released on October 11, 2017

- Don't mask the parent table for single-table inheritance models. (`#561`_)

.. _#561: https://github.com/mitsuhiko/flask-sqlalchemy/pull/561


Version 2.3.1
-------------

Expand Down
2 changes: 1 addition & 1 deletion flask_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from ._compat import itervalues, string_types, to_str, xrange
from .model import DefaultMeta

__version__ = '2.3.1'
__version__ = '2.3.2'

# the best timer function for the platform
if sys.platform == 'win32':
Expand Down
9 changes: 9 additions & 0 deletions flask_sqlalchemy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ def __init__(cls, name, bases, d):

super(NameMetaMixin, cls).__init__(name, bases, d)

# __table_cls__ has run at this point
# if no table was created, use the parent table
if (
'__tablename__' not in cls.__dict__
and '__table__' in cls.__dict__
and cls.__dict__['__table__'] is None
):
del cls.__table__

def __table_cls__(cls, *args, **kwargs):
"""This is called by SQLAlchemy during mapper setup. It determines the
final table object that the model will use.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='Flask-SQLAlchemy',
version='2.3.1',
version='2.3.2',
url='http://github.com/mitsuhiko/flask-sqlalchemy',
license='BSD',
author='Armin Ronacher',
Expand Down
11 changes: 11 additions & 0 deletions tests/test_table_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,14 @@ class User(db.Model):
pass

assert 'could not assemble any primary key' in str(info.value)


def test_single_has_parent_table(db):
class Duck(db.Model):
id = db.Column(db.Integer, primary_key=True)

class Call(Duck):
pass

assert Call.__table__ is Duck.__table__
assert '__table__' not in Call.__dict__

0 comments on commit df7903e

Please sign in to comment.