Skip to content

Improve creation of custom select object #6700

Description

@CaselIT

Discussed in #6693

Originally posted by ShmuelTreiger June 30, 2021
Now that session.query isn't recommended, is there a way to create a custom Select object? Similar to this stackoverflow question: https://stackoverflow.com/questions/15936111/sqlalchemy-can-you-add-custom-methods-to-the-query-object

I've looked around and haven't found anything, just thought I would see if I'm missing something before raising an issue.

So far I have been able to create the custom class and inherit from select, but I have been unable to add it to the session.

class CustomSelect(Select):
    def custom_method(self):
        pass

Session(select_cls=CustomSelect, future=True)

The class works, the session doesn't

As mentioned by Mike here: #6693 (reply in thread)
in 1.4 there is no public api and no documentation on how to subclass a select correctly.

cc @ShmuelTreiger

Activity

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

    sqluse casenot really a feature or a bug; can be support for new DB features or user use cases not anticipated

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions