Error Message "Exception - Call to a member function getLastError() on null"

Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
Number of replies: 24

Dear Sir,

We are using Moodle 3.6.1 (2018120301), CentOS 7,4.108, MySQL 5.7.21, PHP 7.2.16, Theme- Essential 3.6.01 (201812704),

It is the time to prepare new moodle courses of next semester. When we bulk import the courses to the categories, the speed is slow and it prompts the error message "Exception - Call to a member function getLastError() on null."

What's happening? Please kindly help to fix this problem.

Recently, I only fine tuned the MySQL, just increased the innodb_buffer_pool_size and innodb_log_file_size at my.cnf file. And also, installed ghostscript. Is this error related to these changes? It is strange that we can import courses successfully at last semester. However, we encounter this error this new semester.

Please help to solve this problem. Thank you very much.

Best Regards,

Kelvin Ma


Average of ratings: -
In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

Cannot open the .jpg file.

Suggest you copy and paste the text of the debug output into a text editor and save locally as a .txt file.   Then come back here, reply to own posting, then copy and paste the contents of your local .txt file into the posting.

Might provide details of your steps for someone to attempt to reproduce the problem and a clip of what you are using when 'bulk import the courses to the categories'.

Surely there was an entry in web service error logs.  A clip of those entries as well ... that's clip ... not entire log file.

You've mentioned making changes to config of MySQL ... those were?  And since those would affect overall performance of server might be a good idea to provide info on CPU's and Memory of server - assuming single server.   What's the output of the top lines in 'top' command as an example.

'SoS', Ken

In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
I am waiting for the bulk course creation csv file from my supervisor.
I try to provide the information as much as I can.
However, I don't know where I can take the web service error logs.
For debug info, I can't provide it because I haven't turned it on when my supervisor do the course upload.

Best Regards,
Kelvin Ma
Attachment error_message.jpg
Attachment my.cnf.JPG
Attachment top_command.jpg
In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -

Attached is the Moodle log file, The course upload is performed at about 4:30pm.

In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -

Attached is /usr/local/apache2/logs/error_log

HK 4pm = 8am GMT

HK 5pm = 9pm GMT

In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

No offense, Kelvin, but ... *IF* I were commercial support I would be expected to deal with file formats for *clips* of information requested. 

I am NOT 'commercial support' ... and really don't trust documents like .docx's - and I don't care if Moodle forums scan or not ... nothing is 100%.   Why should I ... a non paid person ... risk anything in attempts to help someone for absolutely nothing.   Only first responders do that! (and this isn't something that threatens life and limb!)

By 'clips' (txt) I meant small examples of that were representative ... not entire logs between times in a zip!!!

Will look at things you've provided that I can relatively 'trust', but not more than that ... then get back.

'SoS', Ken

In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

In looking over files that I would open ...

Top command image looks like you should have enough memory. Although some SWAP space is used ... am willing to bet that swap space is your DB server ... see how many Gigs mysqld is using in your image?  And remember, top is realtime ... so mysqld could have shot to the top of top and shown CPU to be pegged at 100% from time to time ... uhhh, please no video of that need be shared here ... just observe and take notes to a text file if top does that.

Image of my.cnf ... can see you made comments ... good habit ... keep that up.

But, how did you determine the settings you added?
Do you have MySQLTuner.pl installed on server?
Do so ... run it with super user credentials (not the DB user and password you see in config.php of Moodle.  Tuner will make recommendations but you need to determine if they should be applied ... it is possible to set some variable and that setting gives diminishing returns.


The logs_date_time.csv file shows to be a dump of mdl_logstore_standard_log ... log of bulk import ... but NOT the actual .csv file used to do the bulk import.
There were, however no errors in it ... but then again ... if an error is serious enough it might never get to the DB to be recorded or one might get what you are reporting.

See https://docs.moodle.org/38/en/Upload_courses
Short file example - there's tons of information @ link above.

RATS!  (read all the screen) ... of above link.

When running into such things, have you thought about breaking that .csv file you are using into 2 parts/halves ... thus not hitting server with as much to do?  Remember, admin person is seldom on server all by themselves and must always consider what users are doing in Moodle as well as what is scheduled and running ... etc.

'SoS', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
Thank you very much for your support and valuable advice. I am sorry that I am just a young man and quite new to Moodle. Your great help and expertise is highly appreciated and respectful.

Q: How did you determine the settings you added?
Moodle DB size is shown as about 3600M at 24-11-2019
According to recommendation, innodb_buffer_pool_size should be as large as Moodle database size.
Take B=3600M
thumb of rule A*2/B=25%
A=3600M*0.25/2=450M
#innodb_log_file_size*2/innodb_buffer_pool_size=450M*2/3600M=25%
innodb_log_file_size = 450M
innodb_buffer_pool_size = 3600M

Q: Do you have MySQLTuner.pl installed on server?
Yes, attached are the MySQLTuner recommendation after last tuned and that I obtain right now.

Best Regards,
Kelvin Ma
In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
My boss have created two dummy files for testing and error reproduction.

He used the below procedures you mentioned to import courses:
Administration->Site administration->Courses->Upload courses->drag and drop files->
Update mode: Create new courses, or update existing ones.

He also used attached testing text file for bulk deletion of dummy course:
Administration->Site administration->Courses->Upload courses->drag and drop files->
Update mode: Create new courses, or update existing ones.
Allow deletes: yes

Sorry for sending you zipped log file. That is nothing special but just file downloaded from Moodle. Please don't mind, just ignore it. I have cropped a sample of it and save it as .txt file. Just want to show you the repeated statements. It is strange that the each action of course creation has repeated a number of times.

One thing more, my boss said the course upload eventually succeeded although there was still one error message shown. The speed becomes much faster after he restart the apache.

Best Regards,
Kelvin Ma
In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

Create

moodle - bulk create courses_test_X20.csv has 705 lines ... thus 704 imports

not counting first line which are the column headings in DB.
When you use that csv file in a spreadsheet (I assume you are using Excel),
do the delimiters ... the ',''s work?
Text between ""'s should be in a cell.

Lot's of XXX's ... which I assume are changed later?

Delete

moodle - bulk delete courses_test_X20.csv

Columns:
fullname,shortname,idnumber,category_path,numsections,showgrades,newsitems,startdate,maxbytes,showreports,enrollable,delete

I don't use this method so educate me ... the word delete at the end?
And do you need all the columns? or just fullname,shortname,idnumber to perform
a delete Just working on the mdl_course table right?

Byte size diff's:
93356 Dec 20 19:26 moodle - bulk create courses_test_X20.csv
98283 Dec 20 19:33 moodle - bulk delete courses_test_X20.csv

?????!!!!

Please RATS (read all the screen) ... https://docs.moodle.org/38/en/Upload_courses

There is other info but ...

Default course values

Those are values that can be set in the web interface for all the fields that are not specified in the CSV file. Note that they are always used when creating a course, but only when specified during update (see Update mode).

Increasing speed

When importing the content of a backup file, or another course, you are advised to enable the setting keeptempdirectoriesonbackup. This will considerably speed up the process of the upload if you are importing multiple times from the same source

'SoS', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
Q: When you use that csv file in a spreadsheet (I assume you are using Excel), do the delimiters ... the ',''s work?
Ans:
We are using csv file, not Excel file. the delimiters works well.

Q:Lot's of XXX's ... which I assume are changed later?
Ans:
Yes, it is a dummy file. XXX are changed later.


Q: And do you need all the columns? or just fullname, shortname, idnumber to perform a delete Just working on the mdl_course table right?

Ans:

It is believed that there should be no problem at the format of the text file. We can import using the file but it stopped somewhere in the middle, If we break the file into smaller pieces which contains fewer records, it works. Last semester, we could just load the text file with more than 700 records, but this time cannot. The file format is not changed, it is generated by the same crystal report.

In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

Ok, but I still don't understand why!!!

What is being imported sets up 700+ shell courses containing info that still has to be changed and with no content nor teachers assigned let alone students enrolled.

And this is done every semester?

So each course has to be visited ... settings changed (XXX to something else), plus adding content, teachers, etc.

Wouldn't it be easier to reset courses ... all students un-enrolled, their assignments removed, gradebook cleared, event logs for course also removed ... teacher could remain ... content remains ... and course ready for new enrollments.

So I still wonder about the error ...  guess ... evidently there is some setting that is NULL which gets trapped or ignored but eventually the shear number of errors for this NULL reaches a max and Moodle can no longer keep up?

'SoS', Ken

In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
Thank you very much for your kind help. You are so helpful that you reply me so much email in forum. May GOD bless you and reward you.

Q: What is being imported sets up 700+ shell courses containing info that still has to be changed and with no content nor teachers assigned let alone students enrolled.
Ans: We would firstly import all the courses. Last semester is F19. The coming semester is W20. The courses would be different. Teachers want to keep their content of last semester, so we have to create new courses under W20. Then we would add teachers and enroll students later. Finally, teachers will add their content on their course.

Q:And this is done every semester?
Ans: Yes, this is done every semester.

Q:So each course has to be visited ... settings changed (XXX to something else), plus adding content, teachers, etc.
Ans: The teachers and students will be bulk imported later.

Q: Wouldn't it be easier to reset courses ... all students un-enrolled, their assignments removed, gradebook cleared, event logs for course also removed ... teacher could remain ... content remains ... and course ready for new enrollments.
Ans: it seems not suitable.

So I still wonder about the error ... guess ... evidently there is some setting that is NULL which gets trapped or ignored but eventually the shear number of errors for this NULL reaches a max and Moodle can no longer keep up?
Ans: I still don't know where the "NULL" come from.

Kelvin
In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

Have something that you could try .... me thinks the only table in moodle that might track errors/NULL's is mdl_logstore_standard_log ... the 'who done it' table.

If you have a clone of production server could try suggested there first.

Seems to me if all courses are starting over there really isn't any need in retaining information in logstore_standard_log table.   Truncate the table.  Run tuner to see if any change.   Then try your import.

It's a strange error.

'SoS', Ken


In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
According to my record, I should have set to truncate the standard log in Moodle GUI in the past. The hint in Moodle recommends not to leave the log less than 30days; otherwise it cannot take statistics. Therefore, I set it to 35days. It should be mdl_logstore_standard_log, right?
Site Administration->Plugin->Manage log stores->Logging->Standard Log->Keep logs for: change from “Never delete logs” to “35days”
In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

mysqltuner

    Run OPTIMIZE TABLE to defragment tables for better performance
      OPTIMIZE TABLE `moodle`.`mdl_logstore_standard_log`; -- can free 102.5 MB
    Total freed space after theses OPTIMIZE TABLE : 102.5 Mb

mdl_logstore_standard_log will always be the largest table as that's the 'who done it' table for moodle.  Closet thing to raw apache logs ... access or error.

That table gets slow ... site gets slow.

Bet if you query it you will see references to what you are trying to do.

and

    innodb_buffer_pool_instances(=4)

From what I've read from Percona blogs about MySQL ... a good resource ... buffer pool instances ... 1 per Gig of innodb_buffer_pool_size ... which you show as 3600M

3600M = how many Gigs -near 4Gigs?

BTW, DB server might need tweaking often ... run Tuner on a schedule of some sort to see if tweaks need upwards.

Next posting ... but before .. with you admining and 'boss' doing is there accurate communications of a technical nature between you two?  Suggest you start doing just small chunks ... so you can see what boss might have missed! smile

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
I have set innodb_buffer_pool_size=4096M, innodb_log_file_size=512M

I have run the below command successfully.
MySQL>OPTIMIZE TABLE moodle.mdl_logstore_standard_log;
In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

Took one of your CSV's and edited it ... looks like:

fullname,shortname,idnumber
ACCT100.01 FINANCIAL ACCOUNTING,ACCT100.01,ACCT100.01
ACCT100.02 FINANCIAL ACCOUNTING,ACCT100.02,ACCT100.02
ACCT100.03 FINANCIAL ACCOUNTING,ACCT100.03,ACCT100.03
ACCT101.01 FUNDAMENTALS OF FINANCIAL ACCOUNTING,ACCT101.01,ACCT101.01
ACCT101.02 FUNDAMENTALS OF FINANCIAL ACCOUNTING,ACCT101.02,ACCT101.02

In uploading, delimiter set to ',' ... if you note above the quotes that were surrounding fullname,shortname,and idnumber are gone.

Had to create the Cateogory prior to uploading the csv.

In your original file, first line had a column heading 'category_path' ... which doesn't exist in mdl_course table and no 'category'

And after uploading the CSV 3.8 has other course defaults in a form below where one uploads.  One of those was category.

I kept reducing your csv and would try it again ... failed again ... until just fullname,shortname,idnumber remained.  Debugging was turned on the entire time ... and no errors ... just 0 courses created.

It was the only way I could do it.

https://docs.moodle.org/38/en/Upload_courses

Does show some of the column headings in your original csv file ... but for me on a CentOS 7 version 3.8+ of Moodle only way was minimal.

I would think the csv needs to match up with mdl_course table.

mysql> explain mdl_course;

'SoS', Ken


In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -

We have tried to remove the double-quotes and reduce the field column in the csv. Unfortunately, the same error message still appeared.

In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
Actually, I realize that we had made a few more change. I don't know if any of them cause the error message. I mark them on a txt file. If you do not mind, please kindly help to check it. Thank you very much.
In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -

Attached is the mdl_course_table.txt of our Moodle.

I checked the record. Before the previous semester, it is true that I can successfully import the bulk course  upload csv file provided by my boss. It contains all the column field headers and category path. Anyway, I have to manually create the category on Moodle in advance.

In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

So you are now able to do what you want to do?

Suggestion I made about course reset ...

Your answer:

"Teachers want to keep their content of last semester"

That's what reset does.  Teacher accounts remain and only students accounts are un-enrolled from reset course + their work.

and your comment:

"it seems not suitable."

Have you tried it?  'seems not' ... doesn't sound like it!

So here's a clip of one of the last .csv's posted.  It's the the end of semester 2019 and you are wanting 1st semester 2020 courses

fullname,shortname,idnumber
XXX-ACCT100.01 FINANCIAL ACCOUNTING,XXX-ACCT100.01,XXX-ACCT100.01

What was XXX above and what does XXX above become?

Am certain other colleges face this same issue ... maybe someone who admins a true college could chime in here and share what they do - 'works for them'.

I admin a fairly large K12 site ... courses are reset by teachers.   First year of that only a couple of teachers had problems with that ... since then ... no issues and teachers do feel in more control ... as it should be.

'SoS', Ken



In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Dave Weninger -
Q:That's what reset does. Teacher accounts remain and only students accounts are un-enrolled from reset course + their work.
Ans:
Sorry, I should reply you more firmly. Resetting the course is absolutely impossible. Our courses code, course titles and sections for each semester are totally different. They vary a lot. Our teachers requested to keep the content life long because these are their life long devotion in teaching. We can only promised to keep their content for 5 years. Therefore, we are still keeping our old version Moodle 2.6 storing 5 years contents for all teachers and courses. This old Moodle is still online and available for teachers to access their content.

XXX-ACCT100.01 For example, it is F20-ACCT100.01 Basic Accounting I at this semester. For next semester, it can become W20-ACCT200.02-04 Advanced Accounting II

I understand it is surely not be an easy task to troubleshoot the problem on the technical aspect. Please help me! It is a nightmare for me. You are expert of Moodle. Please kindly help me as much as you can. Thank you so so much.

Kelvin
In reply to Dave Weninger

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

"You are expert of Moodle. Please kindly help me as much as you can."

Think I've reached my level of expertise then.

I can only guess ... however, moodle 3.6 is no longer supported for bug fixes.

See:

https://docs.moodle.org/dev/Releases#Moodle_3.6

which states:

Bug fixes for general core bugs in 3.6.x ended 11 November 2019 (12 months).
Bug fixes for security issues in 3.6.x will end 11 May 2020 (18 months).
The only suggestion I can offer with 3.6.x ... do the csv import.  Yes, it will die/stop function after a certain number of course creations.   Find the last ... note what it is.  Go back to the csv file used, chop off from the top all those that have been created successfully.  Next run then picks up with creating shells where it left off.  Do that same process until all are created.

You could try to submit a bug report in tracker but as I have shown above 3.6.x stopped getting any general core bug fixes in Nov. of this year.

Have another suggestion ... spin up a fresh 3.7.   Try same process on it.

I tried your csv files on a 3.8+ but only with the top 5 course lines.  It would not work until I stripped out all but the first 3 columns.  No errors reported.  Not in Moodle with debug set to max ... no errors in apache server error logs ... no errors in mysql logs either.

Best of luck!

'SoS', Ken


In reply to Ken Task

Re: Error Message "Exception - Call to a member function getLastError() on null"

by Ken Task -
Picture of Particularly helpful Moodlers

Have one last suggestion ... since the error being reported doesn't show in Moodle debug or Webserver error logs ... nor anywhere that you can tell/find and neither one of us can figure out where the reference to NULL is coming from ...

Do you have php-xdebug extension installed ... that provides extra debugging for php.

php -m |grep xdebug

if above shows nothing in response, it's not loaded.

If above does show a response, disable it.

To disable it:

[root@sos ~]# cd /etc/php.d

nano xdebug.ini

put a semi-colon in front of the line that loads the .so file.

After editing looks like:

; Enable xdebug extension module
; zend_extension=/usr/lib64/php/modules/xdebug.so

; in front disables.

Restart apache services.

Check for loading again ... php -m |grep xdebug

Not there.   Good ... now try whatever again.

This is the very last idea I have.

'SoS', Ken