Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#7862 closed (duplicate)

query result set should use same query object passed into query method.

Reported by: towjzhou@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


This code:

user = get_object_or_404(User, pk=100)
profile = UserProfile.objects.get(user=user)
# Here id(user) != id(profile.user), there are 2 different objects. 
# And will override, in some complex code may be cause bugs.

If use Model instance to do query, results should use these model instance.

Attachments (0)

Change History (3)

comment:1 Changed 6 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

This is a duplicate of #17 as far as I can tell, if this is not correct, feel free to repoen.

comment:2 Changed 6 years ago by ubernostrum

This is indeed a duplicate of #17, which grew far beyond its original scope into a proposal for identity mapping in the ORM.

comment:3 Changed 6 years ago by towjzhou@…

But I always not need the full power of identity mapping like java hibernate does.

The most situation that need identity mapping is:

obj = query_for_obj(xxx=model_instance...)
# now do some thing on obj or pass obj to other_functions
def other_functions(obj):
    obj2 = query_for_obj2(obj=obj)
    # here id(obj2.obj) should equal to id(obj), so can work.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.