openwebwork/webwork2

Error occurs on course copy

Closed this issue · 10 comments

I'm setting up courses for the semester and using the new course copy options. I'm only adding a new course_id, and the selecting all options available (except the course.conf).

Upon creating the course and then logging in, I get the error:

Use of uninitialized value in concatenation (.) or string at template layouts/system.html.ep line 126.

indicating that page_title is empty.

Looking in the database a the _setting table shows both the courseTitle and courseInstitution fields are null and the course I copied from does not have these in the database. Where are these stored if not in the db?

Could this be related to #2497, though that was initially only reported for the admin course?

I am unable to reproduce this. I created a course with no title or institution. Logging into that course gives no errors or warnings. Then I copying that course again not providing a title or institution. Logging into the copy course also gives no errors or warnings. I see in the database that neither course has a title or institution in the setting table. Note that the page_title method checks to see if the courseTitle is set before using it and returns the route title for the current route if it does not. So I don't see how it could give a warning.

The error occurred on my production machine. I also can't reproduce on my development machine.

@drgrice1 Doesn't ->can just determine if there is a code ref for that (in the case of line 122 on system.html.ep) or does it also check if the result is undefined or empty string?

$c->can('page_title') checks to see if the $c object can call a method named "page_title". By default all content generator modules can call that method since it is in the base class. However, a derived class could override the can method and make it return false for a method, and thus preventing it from being called in the templates.

It does not check for anything being undefined or the empty string.

I am able to reproduce this on my production and development machine. I'm using the admin course because I know that one doesn't have a title, but I don't think the admin course is the issue, but it is the admin course lacks a title. Here is what my add new course page looks like, basically I am making a copy of the admin course and wanting to keep the old title. The only thing I enter in above is the new name of the course, admin_copy in my tests.

image

Okay, looking a little closer, it appears that if there is a row in courseID_setting, that sets (name, value) = (courseTitle, NULL), it causes the warning. Deleting this row so there is no courseTitle or setting the course title to an empty string or something non NULL makes the warning go away.

The issue appears is because in my case the admin course has no courseTitle setting, so when it is copied over, it is set to NULL because it doesn't exist in the database.

I'm unsure if the issue is when copying the course title/institution in adding a course, if it should just ignore copying settings that are not set or NULL, or if there needs to be a fall back to deal with the course title being set to NULL in the database.

The only way that I can reproduce this is to literally go into the database and set the value of courseTitle to NULL in the setting table. Then I get the warning without doing any copying. Of course if I copy that course and copy the course title it also gives the warning. So the question is, how are you getting the courseTitle set to NULL in the database? I can't see any way to achieve this with webwork2 without manually doing so in the database. Is this from copying some old course where some previous bug existed that set it this way?

Okay, I finally reproduced it as @somiaj said. Stopping the NULL setting from being created in the database is easy. We can also add a check in the page_title method for an undefined value.

This is the issue I posted a few days ago:

#2497

For me, the issue arose because I copied a course from the original "admin" course, which had no courseTitle in the database. And that was perhaps something that carried over from years ago in a prior version of WeBWorK.

This was fixed in #2516.