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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:22:25+00:00 2026-05-27T23:22:25+00:00

any ideas why this is happening? (Pdb) import copy (Pdb) tmpForm=copy.copy(form1) (Pdb) form1 <cms.forms.MainFeaturedForm

  • 0

any ideas why this is happening?

(Pdb) import copy

(Pdb) tmpForm=copy.copy(form1)
(Pdb) form1
<cms.forms.MainFeaturedForm object at 0x7f05a0493350>
(Pdb) tmpForm
<cms.forms.MainFeaturedForm object at 0x7f05a054e950>

copying form1 to tmpForm (and making sure they’re on different memory addresses) to make sure this behaviour is not happening because form1 is being changed

(Pdb) v1=form1.save(commit=False)
(Pdb) v1.position

as can be seen above, v1.position == None right after a form1.save(commit=False)

(Pdb) v1.image_type=2
(Pdb) v1.Article=article
(Pdb) v1.section=33
(Pdb) v1.save()
(Pdb) v1.position
55L

here I set some values and saved it
the save() function changes v1 position to 55 (that’s expected)

(Pdb) v2=tmpForm.save(commit=False)
(Pdb) v2.position
55L

but now, after I saved v1, v2 (a completly new instance) has a position setted to the same one that was set on v1 (not expected)


in case it helps, here’s the save() function of this object (class Featured):

def save(self):
    if self.Article:
        try:
            featured = Featured.objects.get(Article=self.Article, section=self.section)
            self.hiddenID = featured.hiddenID
            if self.position == None:
                if featured.position == None:
                    self.position = 55
                else:
                    self.position = featured.position

            super(Featured, self).save(force_insert=False, force_update=True)
        except Featured.DoesNotExist:
            self.hiddenID = None
            super(Featured, self).save(force_insert=True, force_update=False)
    else:
        self.hiddenID = None
        super(Featured, self).save(force_insert=True, force_update=False)
  • 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-27T23:22:25+00:00Added an answer on May 27, 2026 at 11:22 pm

    Use copy.deepcopy() rather than copy.copy (wild guess: probably it’s sharing the data dict instance …).

    but now, after I saved v1, v2 (a completly new instance) has a
    position setted to the same one that was set on v1 (not expected)

    That is incorrect. A modelform instance sets self.instance in init and then only works on that. If you copy the reference to form.instance and then modify it outside the form, it will of course be reflected on form.instance.

    deepcopy vs. copy:

    In [1]: import copy
    
    In [2]: a={'foo':'bar'}
    
    In [3]: b={'x': a}
    
    In [4]: bb=copy.copy(b)
    
    In [5]: b['x']['foo']
    Out[5]: 'bar'
    
    In [6]: b['x']['foo'] = 'test'
    
    In [8]: bb['x']['foo']
    Out[8]: 'test'
    
    In [9]: bbb=copy.deepcopy(b)
    
    In [10]: bbb['x']['foo'] = 'y'
    
    In [11]: bb['x']['foo']
    Out[11]: 'test'
    
    In [12]: b['x']['foo']
    Out[12]: 'test'
    
    In [13]: bbb['x']['foo']
    Out[13]: 'y'
    

    The thing is that copy will just copy a value, and the references it contains are preserved. deepcopy() copies a value and all the values it contains.

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

Sidebar

Related Questions

Does any one have any idea why this would be happening? This is some
Any ideas why this won't validate here: http://validator.w3.org/#validate_by_input It seems the form input tags
Any ideas how to fix this? UserService.UserServiceClient userServiceClient = new UserServiceClient(); userServiceClient.GetUsersCompleted += new
Anybody have any ideas? The situation is like this: I have a primary rails
I THINK this line is causing a 3.5K Byte memory leak, any ideas why?
This unix command I haven't got quite working on Mac yet - any ideas
I want to know what this looks like. I don't have any ideas about
Here is the code, any ideas why I get this error? private SQLiteDataAdapter DA_Webfiles;
This is simple text detection video made using an opencv. Any ideas how was
Installing Merb on Ruby Enterprise Edition (OS X) throws this error, any ideas? sudo

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.