Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6785387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:07:14+00:00 2026-05-26T17:07:14+00:00

I have model class CreatedMixin(object): __abstract__ = True @declared_attr def created_by(cls): return Column(Integer, ForeignKey(‘user.user_id’,

  • 0

I have model

class CreatedMixin(object):

    __abstract__ = True

    @declared_attr
    def created_by(cls):
        return Column(Integer, ForeignKey('user.user_id',
                      onupdate="cascade", ondelete="restrict"))

    @declared_attr
    def updated_by(cls):
        return Column(Integer, ForeignKey('user.user_id',
                      onupdate="cascade", ondelete="restrict"))

    created_at = Column(DateTime, nullable=False, default=dt.now())
    updated_at = Column(DateTime, nullable=False, default=dt.now(),
                        onupdate=dt.now())


class Net(Base, CreatedMixin):
    """Net or subnet."""

    cidr = Column(postgresql.CIDR, index = True)
    description = Column(UnicodeText())

    parent_id = Column(Integer, ForeignKey('net.id'))
    parent = relationship("Net", remote_side="Net.id")

   def __init__(self, cidr=''):
       self.cidr = cidr

   def __repr__(self):
       return "%s" % self.cidr

To autofill fields created_by and update_by I use sqlalchemy.orm.events.MapperEvents (SQLAlchemy 0.7) like this:

def created_before_insert_listener(mapper, connection, target):
    # execute a stored procedure upon INSERT,
    # apply the value to the row to be inserted
    #target.calculated_value = connection.scalar(
    #                            "select my_special_function(%d)" 
    #                            % target.special_number)
    target.updated_by = 1

# associate the listener function with CreatedMixin,
# to execute during the "before_insert" hook
event.listen(CreatedMixin, 'before_insert', created_before_insert_listener)

But after run app, got the following error but is not mapped

sqlalchemy.orm.exc.UnmappedClassError: Class 'myapp.model.Net' 

What’s wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:07:15+00:00Added an answer on May 26, 2026 at 5:07 pm

    The problem was quite simple, I use an Mixin in my models and inadvertently added to the basic model of property __abstract__ = True

    Example:

    from sqlalchemy import *
    from sqlalchemy.ext.declarative import declarative_base
    from sqlalchemy.orm import sessionmaker, scoped_session
    
    engine = create_engine('sqlite:///:memory:', echo=True)
    Base = declarative_base(bind=engine)
    Session = scoped_session(sessionmaker(engine))
    
    class Mix(object):
        __abstract__ = True
        id =  Column(Integer, autoincrement=True, primary_key=True)
    
    class User(Base, Mix):
        __tablename__ = 'users'
    
        name = Column(String)
        fullname = Column(String)
        password = Column(String)
    
    Base.metadata.create_all()
    
    u = User()
    print u
    

    But in SQLAlchemy 0.6 it works fine. Perhaps this is a bug of 0.6.
    Update: for more information SQLAlchemy abstract

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model like this: class CreatedMixin(DeclarativeBase): __abstract__ = True @declared_attr def updated_by(cls): return
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model class Article(models.Model): . . language = models.ForeignKey(Language, help_text=Select the article's
I have this model: class Journals(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code, max_length=50) name
I have this model: class blog(models.Model): user = models.ForeignKey(User) mail = models.EmailField(max_length=60, null=False, blank=False)
I have a model: class Cost(models.Model): project = models.ForeignKey(Project) cost = models.FloatField() date =
I have a model: class MyModel(models.Model): ... def save(self): print saving ... def delete(self):
I have this model: class Location < ActiveRecord::Base acts_as_gmappable def gmaps4rails_address #{self.city}, #{self.country} end
I have a model class Transaction(models.Model): sender = models.ForeignKey(MyBankAccount, unique=False, related_name=transactions_sent) receiver = models.ForeignKey(RecipientBankAccount,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.