Hi, all.<div>using PB i wanted to implement some access control check on my copyable objects.</div><div>so i placed that in getStateToCopyFor, all is ok except when i need to perfom some asynchronous call in that method.</div>
<div>ex: (i use twisted 10.1.0)<br><div>...</div><div>def getStateToCopyFor(self, user):</div><div> state = self.getStateToCopy()</div><div> d = user.has_perm() # this do an asynchronous call</div><div> def got_perm(allowed, state):</div>
<div> if not allowed:</div><div> state['secret'] = ''</div><div> return state </div><div> d.addCallback(got_perm, state)</div><div> return d</div><div>... </div></div><div><br></div><div>here user.has_perm performe a database access so it returns a deferred, but when i return that deferred, i got an error saying that 'state' is not a dict (which is quit normal cause it's a deferred).</div>
<div>it seems pb do not handle this case, i know i can put my control logic directly in the view method (where returning a deferred is handled) but this will lead to a lot of code duplication, and i really thought that getStateToCopyFor is made for that purpouse.</div>
<div>so i wanted to ask what's the best way to achieve that ?</div><div><br></div><div>Thankx !</div>