Skip to content

Commit

Permalink
Fix warnings when duplicate model names (#220)
Browse files Browse the repository at this point in the history
Copy the `__module__` from the Django model,
and append `.sa` to the `name` so that it matches
the typical case where this new model will be accessed.
  • Loading branch information
ryanhiebert committed Oct 20, 2021
1 parent ee1f988 commit cdfddca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
13 changes: 11 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
2.5 (2021-10-20)
++++++++++++++++

Fixes:

* Address deprecation warnings for SQLAlchemy 1.4 for duplicate model names (#205)

2.4 (2021-10-07)
++++++++++++++++

Fixes:
* Address some Deprecations Warnings coming from sqlalchemy 1.4 (#212)

* Address some deprecation warnings coming from sqlalchemy 1.4 (#212)

Maintenance:

* adopt isort (#210)

2.3 (2021-09-27)
++++++++++++++++

Fixes:

* Address some Deprecations Warnings coming from sqlalchemy 1.4 (#197) (#199)
* Address some deprecation warnings coming from sqlalchemy 1.4 (#197) (#199)

Tests:

Expand Down
8 changes: 6 additions & 2 deletions aldjemy/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@ def construct_models(metadata):
# because querying happens on sqlalchemy side, we can use only one
# type of queries for alias, so we use 'read' type
sa_model = type(
model._meta.object_name,
model._meta.object_name + ".sa",
bases,
{"table": table, "alias": router.db_for_read(model)},
{
"table": table,
"alias": router.db_for_read(model),
"__module__": model.__module__,
},
)

sa_models[model] = sa_model
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aldjemy"
version = "2.4"
version = "2.5"
description = "SQLAlchemy for your Django models"
authors = ["Mikhail Krivushin"]
license = "BSD 3-Clause \"New\" or \"Revised\" License"
Expand Down
6 changes: 6 additions & 0 deletions test_project/sample/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
from aldjemy.meta import AldjemyMeta


class Group(models.Model):
"""A model with the same name as a Django model to trigger some warnings."""

# https://github.com/aldjemy/aldjemy/issues/205


class Chapter(models.Model):
title = models.CharField(max_length=200)
book = models.ForeignKey("Book", on_delete=models.CASCADE)
Expand Down

0 comments on commit cdfddca

Please sign in to comment.