[Lift] Re: NPE Problem with User.current in CRUDify action
On Sun, Jul 12, 2009 at 2:00 PM, Jeppe Nejsum Madsen je...@ingolfs.dkwrote: On Fri, Jul 10, 2009 at 8:12 PM, David Pollakfeeder.of.the.be...@gmail.com wrote: Okay... I just checked in a change to Lift that allows RequestVars to be reset once the session is known. Please do a build with the latest (if you're not building locally, please wait until Hudson finishes spinning the build) and let me know if it works. Thanks, David Thanks, I tried with these changes and it seems to work! Butthis solution feels a bit hackish to me, maybe out of lack of knowledge about the inner workings of Lift (ie what is a Session transition, and what does it transition from/to :-) There's a huge tension in Lift between the re-writing phase (which happens very, very early) and the session-related servicing phase. The reason that we do rewriting before figuring out how to service the request is because it's important to allow sessionless services to be able to intercept the request. It's also super duper important to have the request normalized for as long as possible during the whole servicing cycle. Thus, I've made sure that the URL rewriting happens before the session is part of the request. It turns out that there is a very good reason to extend the life of the RequestVar to include the re-writing phase. This allows us to cache an RDBMS lookup in the request var. The problem in your case is that your model object caused the RequestVar that holds the current user record to be populated. But it was populated by the sessionvar the holds the primary key to the User. So, there needed to be a mechanism for flushing cached RequestVars that are dependent on SessionVars when the session identifier changes. Thus, the new trait that signals to the RequestVar mechanism that a RequestVar is dependent on a SessionVar and needs to be recalculated if the SessionVar changes. I don't think it's a hack as much as another way to resolve the tension between where the request is demarked, the rewriting/caching happens, and when the session is recognized. When are you supposed to apply the CleanRequestVarOnSessionTransition for instance? Is it Lift internals only or? Of course I could just ignore this and be happy that it works, but I like to know how stuff works underneath the covers :-) /Jeppe -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: NPE Problem with User.current in CRUDify action
David Pollak feeder.of.the.be...@gmail.com writes: [...] So, there needed to be a mechanism for flushing cached RequestVars that are dependent on SessionVars when the session identifier changes. Thus, the new trait that signals to the RequestVar mechanism that a RequestVar is dependent on a SessionVar and needs to be recalculated if the SessionVar changes. I don't think it's a hack as much as another way to resolve the tension between where the request is demarked, the rewriting/caching happens, and when the session is recognized. Ok, makes sense. Thanks for the thorough explanation! /Jeppe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: NPE Problem with User.current in CRUDify action
On Thu, Jul 9, 2009 at 11:44 PM, David Pollakfeeder.of.the.be...@gmail.com wrote: If it's still a problem, a reproducible example would be great! It's not a showstopper, since I can workaround it by reading the User again: def findMap[T](f: CustomCategory = Box[T]) : List[T] = { Log.info(User %s, id=%s.format(User.currentUser, User.currentUserId)) // HACK val curUser = User.currentUserId.flatMap(id = getSingleton.find(id)) findMap(By(account, curUser.open_!.account.is))(f) } I tried to reproduce it with the Lift basic example, but was unable to reproduce it here. This is probably good in that it's not a problem that everybody sees, but bad in the sense that I'll need to do some more digging. I'll see if I can find some time do work through the Lift processing cycle :-) /Jeppe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: NPE Problem with User.current in CRUDify action
On Fri, Jul 10, 2009 at 9:28 AM, Jeppe Nejsum Madsen je...@ingolfs.dkwrote: On Fri, Jul 10, 2009 at 10:35 AM, Jeppe Nejsum Madsenje...@ingolfs.dk wrote: On Thu, Jul 9, 2009 at 11:44 PM, David Pollakfeeder.of.the.be...@gmail.com wrote: If it's still a problem, a reproducible example would be great! I've added some logging statements at various places. The statements below are from the beginning of a request to an CRUDify edit page from an CRUDify list page. It seems your hunch was correct in that CRUDify does seem to do some rewriting in it's Locs In CRUDify, it tries to load the selected object and therefore create a new instance. This creation needs the User.currentUser requestVar. But when the requestvars are being initialized, S.session is empty, so I'm not really sure what the correct order is and when S.session should be available, so let me know if you need more info. The re-writing happens before the session is available. Lemme see if I can make the loading of the objects lazy... that might help a lot. /Jeppe INFO - RequestVarHandler.apply INFO - S.init req=null session=net.liftweb.http.liftsess...@40391ae4 INFO - RequestVarHandler.apply INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$__inited_?=true INFO - AnyVar.is: Value not found set default value _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$_=0 INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$__inited_?=true INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$_=0 INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$__inited_?=true INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$_=1 INFO - RequestVarHandler.set _lift_sv_net.liftweb.http.S$postFuncs$__inited_?=true INFO - AnyVar.is: Value not found set default value _lift_sv_net.liftweb.http.S$postFuncs$_=ListBuffer() INFO - RequestVarHandler.set _lift_sv_net.liftweb.http.S$postFuncs$__inited_?=true INFO - RequestVarHandler.set _lift_sv_net.liftweb.http.S$postFuncs$_=ListBuffer() INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$__inited_?=true INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$_=0 INFO - S.init done INFO - New RewriteRequest parsePath=ParsePath(List(assets, edit, 2875),,true,false) INFO - findForParam in=2875 S.session=Empty INFO - Set default user INFO - SessionVar.findFunc _lift_sv_net.liftweb.mapper.MetaMegaProtoUser$curUserId$_. Session=Empty INFO - AnyVar.is: Value not found set default value _lift_sv_net.liftweb.mapper.MetaMegaProtoUser$curUserId$_=Empty INFO - Sessionvar.setFunc _lift_sv_net.liftweb.mapper.MetaMegaProtoUser$curUserId$_=Empty INFO - Set curUser, id=Empty -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: NPE Problem with User.current in CRUDify action
Okay... I just checked in a change to Lift that allows RequestVars to be reset once the session is known. Please do a build with the latest (if you're not building locally, please wait until Hudson finishes spinning the build) and let me know if it works. Thanks, David On Fri, Jul 10, 2009 at 9:56 AM, David Pollak feeder.of.the.be...@gmail.com wrote: On Fri, Jul 10, 2009 at 9:28 AM, Jeppe Nejsum Madsen je...@ingolfs.dkwrote: On Fri, Jul 10, 2009 at 10:35 AM, Jeppe Nejsum Madsenje...@ingolfs.dk wrote: On Thu, Jul 9, 2009 at 11:44 PM, David Pollakfeeder.of.the.be...@gmail.com wrote: If it's still a problem, a reproducible example would be great! I've added some logging statements at various places. The statements below are from the beginning of a request to an CRUDify edit page from an CRUDify list page. It seems your hunch was correct in that CRUDify does seem to do some rewriting in it's Locs In CRUDify, it tries to load the selected object and therefore create a new instance. This creation needs the User.currentUser requestVar. But when the requestvars are being initialized, S.session is empty, so I'm not really sure what the correct order is and when S.session should be available, so let me know if you need more info. The re-writing happens before the session is available. Lemme see if I can make the loading of the objects lazy... that might help a lot. /Jeppe INFO - RequestVarHandler.apply INFO - S.init req=null session=net.liftweb.http.liftsess...@40391ae4 INFO - RequestVarHandler.apply INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$__inited_?=true INFO - AnyVar.is: Value not found set default value _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$_=0 INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$__inited_?=true INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$_=0 INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$__inited_?=true INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$_=1 INFO - RequestVarHandler.set _lift_sv_net.liftweb.http.S$postFuncs$__inited_?=true INFO - AnyVar.is: Value not found set default value _lift_sv_net.liftweb.http.S$postFuncs$_=ListBuffer() INFO - RequestVarHandler.set _lift_sv_net.liftweb.http.S$postFuncs$__inited_?=true INFO - RequestVarHandler.set _lift_sv_net.liftweb.http.S$postFuncs$_=ListBuffer() INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$__inited_?=true INFO - RequestVarHandler.set _lift_sv_net.liftweb.mapper.DB$$anon$1$DepthCnt$_=0 INFO - S.init done INFO - New RewriteRequest parsePath=ParsePath(List(assets, edit, 2875),,true,false) INFO - findForParam in=2875 S.session=Empty INFO - Set default user INFO - SessionVar.findFunc _lift_sv_net.liftweb.mapper.MetaMegaProtoUser$curUserId$_. Session=Empty INFO - AnyVar.is: Value not found set default value _lift_sv_net.liftweb.mapper.MetaMegaProtoUser$curUserId$_=Empty INFO - Sessionvar.setFunc _lift_sv_net.liftweb.mapper.MetaMegaProtoUser$curUserId$_=Empty INFO - Set curUser, id=Empty -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: NPE Problem with User.current in CRUDify action
Are you doing this as part of an HTTP request or at some other point in the execution of your code (e.g., a background processing thread)? On Tue, Jul 7, 2009 at 5:53 AM, Jeppe Nejsum Madsen je...@ingolfs.dkwrote: Hi, I get an Empty box when using the value of User.current when trying to populate the valid select values for use in a CRUDify edit form: I have this mapped object which I'm trying to edit using CRUDify: class Vehicle extends LongKeyedMapper[Vehicle] with IdPK { [...] object customCategory extends MappedLongForeignKey(this, CustomCategory) { override def validSelectValues = Full(CustomCategory.findMap{cc : CustomCategory = Full(cc.id.is, cc.description.is)}) } [...] I then have this, that uses the current user to populate the valid values: object CustomCategory extends CustomCategory with LongKeyedMetaMapper[CustomCategory] { def findMap[T](f: CustomCategory = Box[T]) : List[T] = { Log.info(User %s, id=%s.format(User.currentUser, User.currentUserId)) findMap(By(id, User.currentUser.open_!.account.is))(f) } When navigating to the edit page for Vehicle, I get this in the log: INFO - User Empty, id=Full(2) So it seems the user id is stored ok, but the RequestVar is not set. Any clues?? /Jeppe -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: NPE Problem with User.current in CRUDify action
Just a normal request from a link in a CRUDify list Sendt fra min iPhone Den 07/07/2009 kl. 18.49 skrev David Pollak feeder.of.the.be...@gmail.com : Are you doing this as part of an HTTP request or at some other point in the execution of your code (e.g., a background processing thread)? On Tue, Jul 7, 2009 at 5:53 AM, Jeppe Nejsum Madsen je...@ingolfs.dk wrote: Hi, I get an Empty box when using the value of User.current when trying to populate the valid select values for use in a CRUDify edit form: I have this mapped object which I'm trying to edit using CRUDify: class Vehicle extends LongKeyedMapper[Vehicle] with IdPK { [...] object customCategory extends MappedLongForeignKey(this, CustomCategory) { override def validSelectValues = Full(CustomCategory.findMap {cc : CustomCategory = Full(cc.id.is, cc.description.is)}) } [...] I then have this, that uses the current user to populate the valid values: object CustomCategory extends CustomCategory with LongKeyedMetaMapper [CustomCategory] { def findMap[T](f: CustomCategory = Box[T]) : List[T] = { Log.info(User %s, id=%s.format(User.currentUser, User.currentUserId)) findMap(By(id, User.currentUser.open_!.account.is))(f) } When navigating to the edit page for Vehicle, I get this in the log: INFO - User Empty, id=Full(2) So it seems the user id is stored ok, but the RequestVar is not set. Any clues?? /Jeppe -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: NPE Problem with User.current in CRUDify action
Okay... I see the code path that could cause this issue. Are you doing any re-writing? Are you accessing User.currentUser in your re-writes? On Tue, Jul 7, 2009 at 5:53 AM, Jeppe Nejsum Madsen je...@ingolfs.dkwrote: Hi, I get an Empty box when using the value of User.current when trying to populate the valid select values for use in a CRUDify edit form: I have this mapped object which I'm trying to edit using CRUDify: class Vehicle extends LongKeyedMapper[Vehicle] with IdPK { [...] object customCategory extends MappedLongForeignKey(this, CustomCategory) { override def validSelectValues = Full(CustomCategory.findMap{cc : CustomCategory = Full(cc.id.is, cc.description.is)}) } [...] I then have this, that uses the current user to populate the valid values: object CustomCategory extends CustomCategory with LongKeyedMetaMapper[CustomCategory] { def findMap[T](f: CustomCategory = Box[T]) : List[T] = { Log.info(User %s, id=%s.format(User.currentUser, User.currentUserId)) findMap(By(id, User.currentUser.open_!.account.is))(f) } When navigating to the edit page for Vehicle, I get this in the log: INFO - User Empty, id=Full(2) So it seems the user id is stored ok, but the RequestVar is not set. Any clues?? /Jeppe -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---