Index: /branches/release-39/lib/MT/Object.pm
===================================================================
--- /branches/release-39/lib/MT/Object.pm (revision 2500)
+++ /branches/release-39/lib/MT/Object.pm (revision 2530)
@@ -1238,10 +1238,16 @@
     my $obj = shift;
     my $oc = MT->request('object_cache') or return;
+
+    my $pk = $obj->primary_key;
+    $pk = join ":", @$pk if ref $pk;
+    my $key = ref($obj). ':' . $pk;
+
     if (@_) {
-        $oc = $oc->{"$obj"};
+        $oc = $oc->{$key};
         delete $oc->{shift} if $oc;
     } else {
-        delete $oc->{"$obj"};
-    }
+        delete $oc->{$key};
+    }
+    1;
 }
 
Index: /branches/release-39/lib/MT/Template/ContextHandlers.pm
===================================================================
--- /branches/release-39/lib/MT/Template/ContextHandlers.pm (revision 2496)
+++ /branches/release-39/lib/MT/Template/ContextHandlers.pm (revision 2530)
@@ -10037,4 +10037,5 @@
             if ($args->{lastn} || $args->{offset}) {
                 $args{'direction'} =  'descend';
+                $so = 'descend';
             } else {
                 $args{'direction'} =  'ascend';
Index: /branches/release-39/lib/MT/Util.pm
===================================================================
--- /branches/release-39/lib/MT/Util.pm (revision 2317)
+++ /branches/release-39/lib/MT/Util.pm (revision 2530)
@@ -923,5 +923,5 @@
 sub make_unique_basename {
     my ($entry) = @_;
-    my $blog = $entry->blog;
+    my $blog = MT::Blog->load($entry->blog_id);
     my $title = $entry->title;
     $title = '' if !defined $title;
Index: /branches/release-39/t/35-tags.dat
===================================================================
--- /branches/release-39/t/35-tags.dat (revision 2518)
+++ /branches/release-39/t/35-tags.dat (revision 2530)
@@ -163,7 +163,7 @@
 { "r" : "1", "t" : "<MTComments lastn=\"1\"><MTCommentEntryID></MTComments>", "e" : "5"}, #112
 { "r" : "1", "t" : "<MTComments lastn=\"1\"><MTCommentIP></MTComments>", "e" : "127.0.0.1"}, #113
-{ "r" : "1", "t" : "<MTComments lastn=\"3\" glue=\",\"><MTCommentAuthorLink></MTComments>", "e" : "John Doe,Comment 3,<a title=\"http://chuckd.com/\" href=\"http://localhost/cgi-bin/mt-comments.cgi?__mode=red;id=14\">Chucky Dee</a>"}, #114
+{ "r" : "1", "t" : "<MTComments lastn=\"3\"><MTCommentAuthorLink>,</MTComments>", "e" : "John Doe,Comment 3,<a title=\"http://chuckd.com/\" href=\"http://chuckd.com/\">Chucky Dee</a>,"}, #114
 { "r" : "1", "t" : "<MTComments lastn=\"1\"><MTCommentEmail></MTComments>", "e" : "johnd@doe.com"}, #115
-{ "r" : "1", "t" : "<MTComments lastn=\"1\"><MTCommentAuthorIdentity></MTComments>", "e" : "<img alt=\"Author Profile Page\" src=\"/cgi-bin/mt-static/images/comment/typekey_logo.png\" width=\"16\" height=\"16\" />"}, #116
+{ "r" : "1", "t" : "<MTComments lastn=\"1\"><MTCommentAuthorIdentity></MTComments>", "e" : "<img alt=\"Author Profile Page\" src=\"http://localhost/mt-static/images/comment/typekey_logo.png\" width=\"16\" height=\"16\" />"}, #116
 { "r" : "1", "t" : "<MTComments lastn=\"1\"><MTCommentURL></MTComments>", "e" : "http://john.doe.com/"}, #117
 { "r" : "1", "t" : "<MTComments lastn=\"1\"><MTCommentOrderNumber></MTComments>", "e" : "1"}, #118
@@ -253,5 +253,5 @@
 { "r" : "1", "t" : "<MTEntries lastn=\"1\" offset=\"3\"><MTIfCategory name=\"foo\">in category</MTIfCategory></MTEntries>", "e" : "in category"}, #201
 { "r" : "1", "t" : "", "e" : ""}, #202
-{ "r" : "1", "t" : "<MTIndexList><MTIndexName>-<MTIndexLink>-<MTIndexBasename>;</MTIndexList>", "e" : "Archive Index-http://narnia.na/nana/archives.html-index;Atom-http://narnia.na/nana/atom.xml-index;JavaScript-http://narnia.na/nana/mt.js-index;Main Index-http://narnia.na/nana/-index;RSD-http://narnia.na/nana/rsd.xml-index;RSS-http://narnia.na/nana/rss.xml-index;Stylesheet-http://narnia.na/nana/styles.css-index;"}, #203
+{ "r" : "1", "t" : "<MTIndexList><MTIndexName>-<MTIndexLink>-<MTIndexBasename>;</MTIndexList>", "e" : "Archive Index-http://narnia.na/nana/archives.html-index;Feed - Recent Entries-http://narnia.na/nana/atom.xml-index;JavaScript-http://narnia.na/nana/mt.js-index;Main Index-http://narnia.na/nana/-index;RSD-http://narnia.na/nana/rsd.xml-index;Stylesheet-http://narnia.na/nana/styles.css-index;"}, #203
 { "r" : "1", "t" : "<MTIfNeedEmail>email needed</MTIfNeedEmail>", "e" : ""}, #204
 { "r" : "1", "t" : "<MTIfAllowCommentHTML>comment html allowed</MTIfAllowCommentHTML>", "e" : "comment html allowed"}, #205
@@ -273,6 +273,6 @@
 { "r" : "1", "t" : "<MTArchiveList archive_type='Daily'><MTArchiveDateEnd></MTArchiveList>", "e" : "January 31, 1978 11:59 PMJanuary 31, 1965 11:59 PMJanuary 31, 1964 11:59 PMJanuary 31, 1963 11:59 PMJanuary 31, 1962 11:59 PMJanuary 31, 1961 11:59 PM"}, #221
 { "r" : "1", "t" : "<MTArchiveList archive_type='Weekly'><MTArchiveDateEnd></MTArchiveList>", "e" : "February  4, 1978 11:59 PMFebruary  6, 1965 11:59 PMFebruary  1, 1964 11:59 PMFebruary  2, 1963 11:59 PMFebruary  3, 1962 11:59 PMFebruary  4, 1961 11:59 PM"}, #222
-{ "r" : "1", "t" : "<MTComments lastn='3'><MTFeedbackScore>,</MTComments>", "e" : "0,0,1.5,"}, #223
-{ "r" : "1", "t" : "<MTComments lastn='3'>,<MTIfNonEmpty tag='CommenterName'><MTCommenterName>: <MTCommenterIfTrusted>trusted<MTElse>untrusted</MTElse></MTCommenterIfTrusted><MTElse><MTCommentAuthor></MTIfNonEmpty></MTComments>", "e" : ",Chucky Dee: trusted,Comment 3,John Doe: trusted"}, #224
+{ "r" : "1", "t" : "<MTComments lastn='3'><MTFeedbackScore>,</MTComments>", "e" : "1.5,0,0,"}, #223
+{ "r" : "1", "t" : "<MTComments lastn='3'>,<MTIfNonEmpty tag='CommenterName'><MTCommenterName>: <MTCommenterIfTrusted>trusted<MTElse>untrusted</MTElse></MTCommenterIfTrusted><MTElse><MTCommentAuthor></MTIfNonEmpty></MTComments>", "e" : ",John Doe: trusted,Comment 3,Chucky Dee: trusted"}, #224
 { "r" : "1", "t" : "<MTTags glue=','><MTTagName> <MTTagRank></MTTags>", "e" : "anemones 4,grandpa 6,rain 2,strolling 6,verse 1"}, #225
 { "r" : "1", "t" : "<MTEntries tag='grandpa' lastn='1'><MTEntryTags glue=','><MTTagRank></MTEntryTags></MTEntries>", "e" : "6,2,6"}, #226
@@ -406,5 +406,5 @@
 { "r" : "1", "t" : "<MTAuthors sort_by='display_name' sort_order='descend'><MTAuthorID>;</MTAuthors>", "e" : "3;2;"}, #354
 { "r" : "1", "t" : "<MTArchives><MTArchiveLabel></MTArchives>", "e" : "EntryMonthlyWeeklyDailyCategoryPage"}, #355
-{ "r" : "1", "t" : "<MTEntries><$MTEntryID$>:<MTComments><MTIfCommenterIsAuthor><MTIfCommenterIsEntryAuthor>2<MTElse>1</MTIfCommenterIsEntryAuthor><MTElse>0</MTIfCommenterIsAuthor>;</MTComments></MTEntries>", "e" : "1:0;0;0;8:0;7:6:2;1;0;5:0;4:"}, #356
+{ "r" : "1", "t" : "<MTEntries><$MTEntryID$>:<MTComments><MTIfCommenterIsAuthor><MTIfCommenterIsEntryAuthor>2<MTElse>1</MTIfCommenterIsEntryAuthor><MTElse>0</MTIfCommenterIsAuthor>;</MTComments></MTEntries>", "e" : "1:0;0;0;8:0;7:6:1;2;0;5:0;4:"}, #356
 { "r" : "1", "t" : "<MTPages id='20'><$MTPageMore$></MTPages>", "e" : "<p>I don't have much to say,</p>"}, #357
 { "r" : "1", "t" : "<MTAssets lastn='1'><$MTAssetlabel$></MTAssets>", "e" : "Image photo"}, #358
@@ -412,5 +412,5 @@
 { "r" : "1", "t" : "<MTPages id='20'><MTPageAssets><$MTAssetID$></MTPageAssets></MTPages>", "e" : "2"}, #360
 { "r" : "1", "t" : "<MTAuthors><$MTAuthorAuthType$>:<$MTAuthorAuthIconURL$>;</MTAuthors>", "e" : "MT:http://localhost/mt-static/images/comment/mt_logo.png;MT:http://localhost/mt-static/images/comment/mt_logo.png;"}, #361
-{ "r" : "1", "t" : "<MTComments><$MTCommenterAuthType$>:<$MTCommenterAuthIconURL$>;</MTComments>", "e" : ":;:;:;:;MT:http://localhost/mt-static/images/comment/mt_logo.png;MT:http://localhost/mt-static/images/comment/mt_logo.png;:;TypeKey:http://localhost/mt-static/images/comment/typekey_logo.png;:;"}, #362
+{ "r" : "1", "t" : "<MTComments><$MTCommenterAuthType$>:<$MTCommenterAuthIconURL$>;</MTComments>", "e" : ":;:;:;:;:;MT:http://localhost/mt-static/images/comment/mt_logo.png;MT:http://localhost/mt-static/images/comment/mt_logo.png;:;TypeKey:http://localhost/mt-static/images/comment/typekey_logo.png;"}, #362
 { "r" : "1", "t" : "<MTAuthors sort_by='id' need_entry='0' ><MTAuthorName>;</MTAuthors>", "e" : "Melody;Chuck D;Bob D;"}, #363
 { "r" : "1", "t" : "<MTAuthors sort_by='id' need_entry='0' status='disabled'><MTAuthorName>;</MTAuthors>", "e" : "Hiro Nakamura;"}, #364
Index: /branches/release-39/t/lib/MT/Test.pm
===================================================================
--- /branches/release-39/t/lib/MT/Test.pm (revision 2451)
+++ /branches/release-39/t/lib/MT/Test.pm (revision 2530)
@@ -200,4 +200,5 @@
     $blog->commenter_authenticators('enabled_TypeKey');
     $blog->save() or die "Couldn't save blog 1: ". $blog->errstr;
+    MT::ObjectDriver::Driver::Cache::RAM->clear_cache();
     diag "Saved blog";
 
@@ -316,4 +317,5 @@
         diag "Saved entry #1";
     }
+    $entry->clear_cache();
 
     $entry = MT::Entry->load(2);
@@ -337,4 +339,5 @@
         diag "Saved entry #2";
     }
+    $entry->clear_cache();
 
     $entry = MT::Entry->load(3);
@@ -360,4 +363,5 @@
         diag "Saved entry #3";
     }
+    $entry->clear_cache();
 
     require MT::Trackback;
