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 6048063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:25:17+00:00 2026-05-23T07:25:17+00:00

The use case is that I have a remote (read slow) database from which

  • 0

The use case is that I have a remote (read slow) database from which I grab some data through ORM mapped classes.

I’d like to store non-db temporary data along side the ORM data and I don’t want to pollute the mapped class namespace (which other people use) with a bunch of temporary attributes just so I can store some object specific data. What I would really like to do is to use these as keys into a dict.

I’ve seen this thread so I know that it can be done, but I don’t like the example of:

def __hash__( self ):
    return id( self ) if self.id is None else hash( self.id )

Because my use case includes a db set auto_increment primary key which won’t exist until after a flush. Potentially changing hashes is one of the no-noes of hashing and I’d like to avoid it.

I could try to fix it if I put a flush in the __hash__ but that feels like way too big a side effect to be a good idea.

So, the question is: is there a good way to use ORM mapped class instances as keys to a dict, or is there another/better way to associate temporary data with an object without polluting it’s namespace?

  • 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-23T07:25:18+00:00Added an answer on May 23, 2026 at 7:25 am

    Consider storing your local, "non-db" data in the appropriate mapped instances as a non-mapped attribute. e.g.

    local_data = {'batsman': 'Sangakkara', 'bowler': 'Swann'}
    mapped_instance_from_query._local_data = local_data
    

    SQLAlchemy will simply ignore unmapped attributes.

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

Sidebar

Related Questions

That is, I'd like to have a tuple of values. The use case on
Have a use case wherein need to maintain a connection open to a database
On a Use Case diagram can you show things that an actor cannot do,
My use case is very simple : I have a GUI application, and inside
I have a table that contains a GEOMETRY data type. SQL Server 2008 ships
Suppose I have a custom collection class that provides some internal thread synchronization. For
I have a program that needs to move a file from one directory to
Use case: A does something on his box and gots stuck. He asks B
Use case: 3rd party application wants to programatically monitor a text file being generated
My use case is this, I want to call out to a webservice and

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.