Merge lp:~jtv/launchpad/bug-536769 into lp:launchpad
| Status: | Merged | ||||
|---|---|---|---|---|---|
| Approved by: | Jelmer Vernooij on 2010-03-11 | ||||
| Approved revision: | no longer in the source branch. | ||||
| Merged at revision: | not available | ||||
| Proposed branch: | lp:~jtv/launchpad/bug-536769 | ||||
| Merge into: | lp:launchpad | ||||
| Diff against target: |
59 lines (+12/-3) 2 files modified
database/schema/security.cfg (+2/-1) lib/lp/translations/tests/test_translationtemplatesbuildbehavior.py (+10/-2) |
||||
| To merge this branch: | bzr merge lp:~jtv/launchpad/bug-536769 | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Michael Nelson (community) | code | Approve on 2010-03-11 | |
| Jelmer Vernooij (community) | code mentat | 2010-03-10 | Approve on 2010-03-11 |
|
Review via email:
|
|||
Commit Message
Give buildd manager access to BranchJob.
Description of the Change
= Bug 536769 =
The buildd master needs database access to TranslationTemp
This means giving SELECT and DELETE privileges on BranchJob to fiera.
An update to the TranslationTemp
To test:
{{{
./bin/test -vv -t test_translatio
}}}
To Q/A: go through the instructions at https:/
Note that this is not a schema change as such, and so does not need to go into db-devel.
No lint.
Jeroen
| Michael Nelson (michael.nelson) wrote : | # |
I've got nothing to add to Jelmer's review.
I did have one question for my own learning though: is this the type of thing you were *against* using the with statement for? ie. creating a context manager that also switched back so that you could do:
with dbUserAs(
...
?
@jelmer: I remembered after our conversation, the review type should be code*. Thanks for the review! I nice easy one to start with :-)
| Jeroen T. Vermeulen (jtv) wrote : | # |
Hi Jelmer,
Thanks for the review.
> 45 + def _becomeBuilddMa
> 46 + """Log into the database as the buildd master."""
> 47 + transaction.
> ^^^ Is the transaction.
> work ?
Good question to ask! In this case, yes, we're switching database identities. And you can't do that in the same transaction, so flushing wouldn't make the most recent data changes visible.
This is a pattern we come across sometimes in our test: you want to test what you do on the database under realistic permissions, but those permissions aren't enough to set up your test data. The only choice is to commit and switch identities. And not do it too often, of course. :-)
Jeroen
| Jeroen T. Vermeulen (jtv) wrote : | # |
Hi Michael,
> I did have one question for my own learning though: is this the type of thing
> you were *against* using the with statement for? ie. creating a context
> manager that also switched back so that you could do:
No, actually. I do believe Robert noted that that's a bad thing to do when changing directories in production code, but of course that's a far cry from a temporary state in a unit test.
For the record: what I object to in "with" is the exception-handling design of the context-manager protocol. It mixes two completely different goals that I think should not be combined: a "conditional catch/re-raise" that invites clever, obscure, and brittle control flow; and a simple "enter/exit" mechanism that makes "finally" clauses a bit easier to write. (The latter is helpful, though I still have the separate and minor gripe that it puts burdens on the calling code that from a C++ standpoint should be contained in the class that gives rise to them. But "with" did become a real improvement over "finally" with the more recent support for multiple context managers in a single block.)
The justifying use-case for the IMHO dangerous mixing of "conditional catch/re-raise" and "enter/exit" was a transaction handler that would commit implicitly if no exception was raised. Bad idea! That kind of design can work in very limited cases, but it's brittle to the point of irresponsibility. If you want that sort of thing, separate the two: (1) a transaction manager that aborts if not explicitly committed by exit time—note: no need to meddle with exceptions. And (2) a control-flow construct that commits the transaction if the contained block exits normally—note: an explicit commit at the end of the block expresses this about as well, in less code, without breaking up the order of events; and if necessary a conventional function call can give you the same "if we get to the end of all this, commit in a single place" structure.
Once these two things are bound into one context manager, what happens when you discover you need different behavior with particular exception paths? (a) Go back to custom control flow, which is now the suspicious thing to do. (b) Do a little exception dance to present the context manager with the expected situations at block exit. (c) Have more transaction managers (a hierarchy?) for the same resource but with different exception behaviors. All of these are bad.
To me, it would have made more sense to start out with a simpler enter/exit mechanism and see what else is really needed for code instrumentation, customized control flow, or whatever. But that involves weaseling out of fun and challenging design discussions for cool features, and standing up to the snake who says "taste this, it will give you the knowledge of exceptions and God-like power over control flow."
Did someone mention that there's no single right way to do things unless you're Dutch? They say we have opinions on everything. :)
> with dbUserAs(
> ...
>
> ?
Is there any need to switch back afterwards? I thought this was part of normal test isolation.
Jeroen

One minor comment:
19 === modified file 'lib/lp/ translations/ tests/test_ translationtemp latesbuildbehav ior.py' translations/ tests/test_ translationtemp latesbuildbehav ior.py 2010-03-06 04:57:40 +0000 translations/ tests/test_ translationtemp latesbuildbehav ior.py 2010-03-10 18:05:30 +0000 TemplatesBuildB ehavior( TestCaseWithFac tory): platesBuildBeha vior`." "" eLayer ssLayer ster(self) : commit( ) commit( ) really necessary here, would a Store.flush not work ?
20 --- lib/lp/
21 +++ lib/lp/
38 @@ -81,7 +83,12 @@
39 class TestTranslation
40 """Test `TranslationTem
41
42 - layer = ZopelessDatabas
43 + layer = LaunchpadZopele
44 +
45 + def _becomeBuilddMa
46 + """Log into the database as the buildd master."""
47 + transaction.
^^^ Is the transaction.
48 + self.layer. switchDbUser( config. builddmaster. dbuser) self): latesBuildBehav ior.
49
50 def _makeBehavior(
51 """Create a TranslationTemp