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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:14:28+00:00 2026-05-31T12:14:28+00:00

My setup looks roughly like this: # account/models.py Account(models.Model): The user profile user =

  • 0

My setup looks roughly like this:

# account/models.py
Account(models.Model):
    """ The user profile """
    user = models.OneToOneField("auth.User", primary_key=True, related_name="account")
    balance = models.DecimalField(max_digits=32, decimal_places=2, default=0)
    activation_key = models.CharField(max_length=32)
    ...

And I have a signal handler that looks like this:

def recalculate_credit(sender, instance=None, created=None, **kwargs):

    print(instance.user.account.activation_key)

    account = instance.user.get_profile()

    print(account.activation_key)

    account.calculate_balance()
    account.save()

I’ve added the print statements there to highlight the problem. During my registration process, I set the activation_key property, save, and then this signal is fired later. The first print statement returns that activation key, the second returns ''.

How is this possible? Am I missing something in how .get_profile() works? The code above is actually removing the activation_key value from the user account. Is there some lazy loading going on, or object caching that I’m not aware of?

  • 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-31T12:14:29+00:00Added an answer on May 31, 2026 at 12:14 pm

    Yeah, so what’s going on here is that django doesn’t re-load the .account attr or the value of .get_profile() from the DB every time, it’a cached after the first access. To fix, either get a totally fresh copy from the DB with Account.objects.get(id=user.account_id) when you need to guarantee that the object is fresh, or only access the related Account object through either the .get_profile() API or the .account related descriptor – not both. As long as you access the object in the same way that you did before calling .save() on it, you shouldn’t have this issue.

    Conceptually, the underlying issue is that Django doesn’t do any identity mapping – Foo.objects.get(id=1), run twice, will result in two separate Foo objects in memory. Their attributes won’t be shared, and updating one won’t change the other. It’s more appropriate to consider them “snapshots” of what that model’s DB row looked like when it was retrived from the DB. To find out what the DB value is right now, you have to run the query again.

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

Sidebar

Related Questions

I have a ListView setup in details mode that looks like this: When the
This time my setup looks like this: one table with galleries names CREATE TABLE
I'm using MonoTouch and my application setup looks something like this, NavController -TabBarController -NavController
Noob question here, my basic setup looks like this: (function($) { $.fn.imageSlider = function(options)
Sorry for the log4net newb quesiton, this looks like a common setup, but I
Ok I have a page setup that looks like this: <div class=parent>Content here</div> I
I currently have a unittest.TestCase that looks like.. class test_appletrailer(unittest.TestCase): def setup(self): self.all_trailers =
Here is how setup looks like: ApplicationServer - GlassFish Database Server - Oracle 10g2
All, I originally had my setup like this and everything worked as expected. WEB-INF
We're running on Glassfish 3.0.1 and using Hibernate 3.5.3. Our project setup looks like

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.