Issue 1:
Migrated issue, originally created by Daniel Kassen

Below is a snippet of code that defines a Parent class and a Child class which is abstract and used for inheritance. Classes that inherit from Child do not automatically populate if the entry exists in the database. By that, I mean the proper query is not performed to automatically pull that object out from the database even though it exists, causing duplicate entry errors when commit()'ing the session.

class Parent(Base):
__tablename__ = 'parent'

id = Column(Integer, primary_key=true)
name = Column(String(100, collation='utf8_bin'),
nullable=False, unique=True)

class Child(Base):
__abstract__ = True

@classmethod
def _classname(cls):
return cls.__name__

@delcared_attr
def __tablename__(self):
return self._classname().lower()

@delcared_attr
def id(self):
return Column(Integer, ForeignKey(Parent.id), primary_key=True)

@declared_attr
def parent(self):
return relationship(Parent)

Creating a factory that declares a class with the same attributes as are declared above in the Child class actually works, which is why this isn't very high priority, but it does make my code much less pythonic. Classes created from the factory below auto-populate as they should.

def create_child(name):
class Child(Base):

__tablename__ = name.lower()

id = Column(Serial, ForeignKey(Parent.id), primary_key=True)

parent = relationship(Parent)

Child.__name__ = name
return Child

Issue 2:
Describe the bug

I try to build the documentation into epub format to be able to read the docs on my ebook reader, as I couldn't find the pre-built epub anywhere on the https://www.sqlalchemy.org/.

Unfortunately, this fails with the error.

I tried make html to see if that's a general issue or only an issue with epub, and the make html works successfully.

To Reproduce

$ git clone git@github.com:sqlalchemy/sqlalchemy.git
$ cd sqlalchemy/doc/build/
$ git checkout rel_1_4_31
$ python3.10 -m venv venv
$ . venv/bin/activate
$ python --version
Python 3.10.0
$ pip install -r requirements.txt
$ pip install sphinx
$ pip freeze
alabaster==0.7.12
Babel==2.9.1
certifi==2021.10.8
changelog==0.5.8
charset-normalizer==2.0.12
docutils==0.17.1
idna==3.3
imagesize==1.3.0
Jinja2==3.0.3
libsass==0.21.0
Mako==1.1.6
MarkupSafe==2.1.0
packaging==21.3
Pygments==2.11.2
pyparsing==3.0.7
pytz==2021.3
requests==2.27.1
six==1.16.0
snowballstemmer==2.2.0
Sphinx==4.4.0
sphinx-paramlinks @ git+https://github.com/sqlalchemyorg/sphinx-paramlinks.git@acedb03149e3f87ff599174b033754c2f58f1c95
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
urllib3==1.26.8
zzzeeksphinx @ git+https://github.com/sqlalchemyorg/zzzeeksphinx.git@715c91f45c7b46e7c39528cae964f0d0891b421a
$ make epub

Error

After $ make epub:

sphinx-build -b epub -d output/doctrees -T -j auto . output/epub
Running Sphinx v4.4.0
making output directory... done
building [mo]: targets for 0 po files that are out of date
building [epub]: targets for 168 source files that are out of date
updating environment: [new config] 168 added, 0 changed, 0 removed
reading sources... [100%] tutorial/engine .. venv/lib/python3.10/site-packages/sphinx/ext/autosummary/templates/autosummary/module
waiting for workers...
reading changelog note files (version 1.3.25)...[100%] 6392.rst
reading changelog note files (version 1.3.25)...[100%] 6392.rst
/Users/dstasczak/tmp/sqlalchemy/doc/build/tutorial/tutorial_nav_include.rst:9: ERROR: Undefined substitution referenced: "prev".
/Users/dstasczak/tmp/sqlalchemy/doc/build/tutorial/tutorial_nav_include.rst:9: ERROR: Undefined substitution referenced: "next".
/Users/dstasczak/tmp/sqlalchemy/doc/build/tutorial/tutorial_nav_include.rst:13: ERROR: Undefined substitution referenced: "next".
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/ext/autosummary/templates/autosummary/base.rst:3: ERROR: Error in "currentmodule" directive:
maximum 1 argument(s) allowed, 3 supplied.

.. currentmodule:: {{ module }}
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/ext/autosummary/templates/autosummary/class.rst:3: ERROR: Error in "currentmodule" directive:
maximum 1 argument(s) allowed, 3 supplied.

.. currentmodule:: {{ module }}
WARNING: invalid signature for autoclass ('{{ objname }}')
WARNING: don't know which module to import for autodocumenting '{{ objname }}' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)
WARNING: invalid signature for automodule ('{{ fullname }}')
WARNING: don't know which module to import for autodocumenting '{{ fullname }}' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/ext/autosummary/templates/autosummary/module.rst:53: ERROR: Unknown directive type "autosummary".

.. autosummary::
:toctree:
:recursive:
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/ext/autosummary/templates/autosummary/module.rst:56: WARNING: Explicit markup ends without a blank line; unexpected unindent.
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/ext/autosummary/templates/autosummary/module.rst:58: WARNING: Definition list ends without a blank line; unexpected unindent.
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/ext/asyncio/scoping.py:docstring of sqlalchemy.ext.asyncio.session.connection:12: WARNING: Inline strong start-string without end-string.
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/ext/asyncio/scoping.py:docstring of sqlalchemy.ext.asyncio.session.stream:4: WARNING: Explicit markup ends without a blank line; unexpected unindent.
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/ext/asyncio/session.py:docstring of sqlalchemy.ext.asyncio.session.AsyncSession.connection:8: WARNING: Inline strong start-string without end-string.
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/orm/collections.py:docstring of sqlalchemy.orm.collections.collection:1: WARNING: duplicate object description of sqlalchemy.orm.collections.collection, other instance in orm/collections, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/doc/build/orm/contextual.rst:4: WARNING: Duplicate explicit target name: "threading.local()".
/Users/dstasczak/tmp/sqlalchemy/doc/build/orm/extensions/mypy.rst:4: WARNING: Duplicate explicit target name: "mypy".
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/util/langhelpers.py:docstring of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute:1: WARNING: duplicate object description of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute, other instance in orm/internals, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/util/langhelpers.py:docstring of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute:1: WARNING: duplicate object description of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute, other instance in core/foundation, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/util/langhelpers.py:docstring of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute:1: WARNING: duplicate object description of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute, other instance in core/metadata, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/doc/build/core/reflection.rst:142: ERROR: Unknown interpreted text role "method".
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/util/langhelpers.py:docstring of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute:1: WARNING: duplicate object description of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute, other instance in core/metadata, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/util/langhelpers.py:docstring of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute:1: WARNING: duplicate object description of sqlalchemy.util.langhelpers.HasMemoized.memoized_attribute, other instance in core/selectable, use :noindex: for one of them
docstring of sqlalchemy.sql.expression.LABEL_STYLE_TABLENAME_PLUS_COL:6: WARNING: Inline literal start-string without end-string.
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.CHAR:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.CHAR, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.NCHAR:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.NCHAR, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.NVARCHAR:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.NVARCHAR, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.TEXT:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.TEXT, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.VARCHAR:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.VARCHAR, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.BINARY:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.BINARY, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.BLOB:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.BLOB, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.BOOLEAN:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.BOOLEAN, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.DATE:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.DATE, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.VARBINARY:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.VARBINARY, other instance in core/type_basics, use :noindex: for one of them
/Users/dstasczak/tmp/sqlalchemy/lib/sqlalchemy/sql/sqltypes.py:docstring of sqlalchemy.sql.sqltypes.REAL:1: WARNING: duplicate object description of sqlalchemy.sql.sqltypes.REAL, other instance in core/type_basics, use :noindex: for one of them
changelog/changelog_07.rst:5: WARNING: Explicit markup ends without a blank line; unexpected unindent.
/Users/dstasczak/tmp/sqlalchemy/doc/build/changelog/changelog_11.rst:1: WARNING: Inline emphasis start-string without end-string.
looking for now-outdated files... none found
pickling environment... done
checking consistency... /Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/Jinja2-3.0.3.dist-info/LICENSE.rst: WARNING: document isn't included in any toctree
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/MarkupSafe-2.1.0.dist-info/LICENSE.rst: WARNING: document isn't included in any toctree
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/alabaster-0.7.12.dist-info/DESCRIPTION.rst: WARNING: document isn't included in any toctree
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/imagesize-1.3.0.dist-info/LICENSE.rst: WARNING: document isn't included in any toctree
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/ext/autosummary/templates/autosummary/base.rst: WARNING: document isn't included in any toctree
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/ext/autosummary/templates/autosummary/class.rst: WARNING: document isn't included in any toctree
/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/ext/autosummary/templates/autosummary/module.rst: WARNING: document isn't included in any toctree
done
preparing documents... done
The name of the builder is: epubThe name of the builder is: epub
Traceback (most recent call last):
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/mako/lookup.py", line 249, in get_template
return self._check(uri, self._collection[uri])
KeyError: 'page.mako'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/builders/html/__init__.py", line 1055, in handle_page
output = self.templates.render(templatename, ctx)
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/zzzeeksphinx/mako.py", line 102, in render
return self.lookup.get_template(template).render_unicode(**context)
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/mako/lookup.py", line 262, in get_template
raise exceptions.TopLevelLookupException(
mako.exceptions.TopLevelLookupException: Cant locate template for uri 'page.mako'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/cmd/build.py", line 284, in build_main
app.build(args.force_all, filenames)
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/application.py", line 337, in build
self.builder.build_update()
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 294, in build_update
self.build(to_build,
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 358, in build
self.write(docnames, list(updated_docnames), method)
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 529, in write
self._write_parallel(sorted(docnames),
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 556, in _write_parallel
self.write_doc(firstname, doctree)
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/builders/_epub_base.py", line 374, in write_doc
super().write_doc(docname, doctree)
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/builders/html/__init__.py", line 632, in write_doc
self.handle_page(docname, ctx, event_arg=doctree)
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/builders/_epub_base.py", line 467, in handle_page
super().handle_page(pagename, addctx, templatename, outfilename, event_arg)
File "/Users/dstasczak/tmp/sqlalchemy/doc/build/venv/lib/python3.10/site-packages/sphinx/builders/html/__init__.py", line 1062, in handle_page
raise ThemeError(__("An error happened in rendering the page %s.\nReason: %r") %
sphinx.errors.ThemeError: An error happened in rendering the page changelog/changelog_01.
Reason: TopLevelLookupException("Cant locate template for uri 'page.mako'")

Theme error:
An error happened in rendering the page changelog/changelog_01.
Reason: TopLevelLookupException("Cant locate template for uri 'page.mako'")
make: *** [epub] Error 2

Versions

OS: macOS Mojave Version 10.14.6 (18G9323)

Python: 3.10.0

SQLAlchemy: rel_1_4_31

Database: None

DBAPI (eg: psycopg, cx_oracle, mysqlclient): None

Additional context

No response