Opened 10 years ago

Closed 10 years ago

Last modified 10 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: no UI/UX: no


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.

Change History (3)

comment:1 Changed 10 years ago by Alex Gaynor

Resolution: duplicate
Status: newclosed

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

comment:2 Changed 10 years ago by James Bennett

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 10 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.
Note: See TracTickets for help on using tickets.
Back to Top