This project is archived and is in readonly mode.
default_scope doesn't work at a late point
-
Rohit Arondekar
- State changed from new to open
- Assigned user set to José Valim
- Importance changed from to High
This issue: 4427 must be happening because of this. Although I couldn't reproduce that one in RC 1.
Assigning to Jose as this looks important.
-
Jan Xie
#4427 Strange behaviour in exception display looks like a different problem.
I guess add a line in default_scope to clear Thread.current[key] will resolve this problem?
-
José Valim
- Assigned user changed from José Valim to Rohit Arondekar
Can you guys provide a patch with tests? Rohit?
-
Jan Xie
- Tag changed from activerecord, default_scope, thread to activerecord, default_scope, patch, thread
Here's a patch with tests.
-
Rohit Arondekar
- Importance changed from High to Low
Jan, am I correct in saying that this will have a performance penalty?
Also I've lowered the priority as I had thought it was related to the other ticket. Apologies.
-
Jan Xie
Do you mean reset_scoped_methods in default_scope will cause the following run more times?
Thread.current[key] = Thread.current[key].presence || self.default_scoping.dupdefault_scope only runs when model classes loading, so I think this is not a big problem?
Also correctness should be the first goal? ;)
-
Rohit Arondekar
One more doubt, this one is more serious though — the test passes without the fix. I commented out the
reset_scoped_methodsand ran the suite:(ruby-1.9.2@3-dev)(~/projects/rails/activerecord)९ rake test_sqlite3 TEST=test/cases/base_test.rb 2>/dev/null (in /home/rohit/projects/rails/activerecord) Using native SQLite3 Loaded suite /home/rohit/.rvm/gems/ruby-1.9.2-p0@3-dev/gems/rake-0.8.7/lib/rake/rake_test_loader Started ............................................................................................................................ Finished in 1.197417 seconds. 124 tests, 305 assertions, 0 failures, 0 errors, 0 skips Test run options: --seed 15670Shouldn't the test fail without the fix?
-
Jan Xie
The real problem is default_scope doesn't merge where clauses correctly. Sorry for my inaccurate description in original ticket.
-
Jan Xie
The new test I added is in relation_scoping_test.rb, try with TEST=test/cases/relation_scoping_test.rb?
-
Rohit Arondekar
- Assigned user changed from Rohit Arondekar to Aaron Patterson
Sorry! Tried
base_test.rb:(+1 test fails without the fix and the patch applies cleanly.
-
Repository
- State changed from open to resolved
(from [f2945401541616c1449799f41a510c8c4f019b8b]) default scope merge where clauses [#5488 default_scope doesn't work at a late point state:resolved] http://github.com/rails/rails/commit/f2945401541616c1449799f41a510c...
-
Repository
(from [21beedf1ff925613fb1ca9b3cf44d10526b64a2e]) default scope merge where clauses [#5488 default_scope doesn't work at a late point state:resolved] http://github.com/rails/rails/commit/21beedf1ff925613fb1ca9b3cf44d1...
