Opened 7 years ago

Closed 7 years ago

Last modified 7 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:

Description

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 user.save() will override profile.user.save(), 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 7 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 7 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 7 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 obj2.obj.save() can work.
Note: See TracTickets for help on using tickets.
Back to Top