Forum OpenACS Development: General Comment editing issue

Collapse
Posted by Jim Lynch on
WP uses General Comments (not sure that's relevent yet) and I seem to have found a coupla issues...

When viewing a WP slide, it shows that I can add comments which get associated to that slide. So, testing this, I add a comment, and it seems to work.

Go back to the slide, and there's my comment and a link for editing it. I click on it, and a dialog shows up with the expected comment.

I edit the comment, make sure it's live and then go back to the page, which now has the new comment and again an "edit your comment" link, which I click, but this time the dialog has the wrong revision as the default text.

So that's the problem... and now, what I want is to have someone see if this problem is present on something commentable other than a wimpy point slide. Anyone willing?

-Jim

So, I fixed the general comment page, and as a result found a problem which is located in core:

If you do something like...

db_multirow mu st {
  select
    f.foo, 
    f.bar
  from
    table f
}

(notice no code block) then the vars foo and bar will appear in the multirow and NOT leak into the template stack frame, so if you've done [set foo something] beforehand, foo will retain its value because the copy of foo altered by the query will not change the copy of foo that you would have set before the db_multirow call.

BUT

if you add a code block, like this:

db_multirow mu st {
  select
    f.foo, 
    f.bar
  from
    table f
} { 
    anything here, including nothing
}

then ALL vars (incl any defined in -extend) will leak into the calling frame.

This behavior is confusing, bug-causing and produces unmaintainability in other packages. It needs to be fixed as soon as possible.

Hi Jim

I agree that's probably not what you would intuitively expect with db_multirow, but that behaviour is documented - you can use the -unclobber parameter to not overwrite local variables.

https://openacs.org/api-doc/proc-view?proc=db_multirow&source_p=1&version_id=

cheers!
Brian

Heya Brian...

Thing is, it's inconsistant. If you don't supply a code block, it doesn't overwrite the vars. If you do supply the code block, the vars "should" (IMO) only be visible within it. I didn't know about the unclobber thing tho. Looking at db_foreach, there's no such issue, or at least no "-unclobber" option. For consistancy's sake, it should be the opposite: if, on the small chance, someone wants the vars visible beyond the block, there should be a -clobber option, and it should also be in loops like db_foreach.

If you like, you can apply the concept from "Apple User Interface Guidelines": don't make (the programmer) remember any more than he has to, certainly not: "so there's a foreach, a db_foreach, a db_multirow, and in only one of those, vars are clobbered outside a supplied block, and then only when it's supplied"... nightmarish... That's exactly the kind of thing that's going to chase devs away.

-Jim

Jim

This code block

foreach value [list a b c] {
#do something
}

the varaible "value" is still set after the foreach code block. db_foreach and db_multirow behave exactly the same way.

So for a Tcl programmer it is expected behavior. The only thing you need to remember is that the variables matching the columns in the query are created within the loop so they can overwrite variables in the caller since that is the level the code block runs at, and they exist in the caller's level after the code block completes.

Actually unclobber only works if the variable was previously set. If it was not set before the multirow it will not be cleaned up after the multirow so you end up with new variables.

This makes it tricky with using template::list since naturally you want the filter names to match the varaible the filter is filtering for, and if the filter is not set, it will be set at the end of the multirow causing the filter to be applied incorrectly.

Not sure, are you saying the behavior is inconsistant but this is needed because db_multirow is used with template::list?

-Jim

Collapse
Posted by Jim Lynch on
hmm. in that case it's not inconsistant... ok, never mind :)