Bug 24001 - Cannot edit card template
Summary: Cannot edit card template
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Label/patron card printing (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low major (vote)
Assignee: Alexis Ripetti
QA Contact: Testopia
URL:
Keywords:
: 27517 (view as bug list)
Depends on:
Blocks: 17258
  Show dependency treegraph
 
Reported: 2019-11-08 11:55 UTC by Jonathan Druart
Modified: 2023-06-08 22:26 UTC (History)
11 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact: Martin Renvoize
Documentation submission:
Text to go in the release notes:
This fixes errors that caused creating and editing patron card templates and printer profiles to fail.
Version(s) released in:
22.05.00,21.11.06,21.05.16


Attachments
Bug 24001: Cannot edit card template (1.22 KB, patch)
2019-12-03 18:14 UTC, Chris Nighswonger
Details | Diff | Splinter Review
[PATCH] Bug 24001: Cannot edit card template (441 bytes, patch)
2020-02-11 17:17 UTC, Rinrada Wongsaichua
Details | Diff | Splinter Review
Bug 24001: Fix patron card template edition (1.20 KB, patch)
2020-02-18 10:02 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 24001: Fix patron card template edition (1.70 KB, patch)
2020-06-30 16:55 UTC, Blou
Details | Diff | Splinter Review
Bug 24001: Fix patron card template edition (1.76 KB, patch)
2020-09-08 19:12 UTC, Alexis Ripetti
Details | Diff | Splinter Review
Bug 24001: Fix Card template/rpinter profile creation and edit (2.91 KB, patch)
2022-03-04 16:27 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 24001: Fix patron card template edition (1.76 KB, patch)
2022-03-08 16:59 UTC, The Minh Luong
Details | Diff | Splinter Review
Bug 24001: Fix Card template/rpinter profile creation and edit (1.79 KB, patch)
2022-03-08 16:59 UTC, The Minh Luong
Details | Diff | Splinter Review
Bug 24001: Fix patron card template edition (1.81 KB, patch)
2022-04-27 14:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 24001: Fix Card template/rpinter profile creation and edit (1.83 KB, patch)
2022-04-27 14:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 24001: Fix patron card template edition (1.87 KB, patch)
2022-04-27 15:21 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 24001: Fix Card template/rpinter profile creation and edit (1.90 KB, patch)
2022-04-27 15:21 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 24001: Fix patron card template edition (1.92 KB, patch)
2022-04-27 15:24 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 24001: Fix Card template/rpinter profile creation and edit (1.94 KB, patch)
2022-04-27 15:24 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 24001: Fix patron card template edition (1.93 KB, patch)
2022-04-27 16:14 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 24001: Fix Card template/rpinter profile creation and edit (1.95 KB, patch)
2022-04-27 16:14 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 24001: (follow-up) Fix t_Profile.t (823 bytes, patch)
2022-04-29 06:25 UTC, Fridolin Somers
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2019-11-08 11:55:24 UTC
To recreate:
- Go to Home › Tools › Patron card creator › Templates 
- New > Card template
- Save
- Edit
- Save

=>
Can't bless non-reference value at /home/vagrant/kohaclone/C4/Creators/Profile.pm line 89
        C4::Creators::Profile::retrieve('C4::Patroncards::Profile', 'profile_id', 22, 'creator', 'Patroncards') called at /home/vagrant/kohaclone/C4/Patroncards/Profile.pm line 29                                        C4::Patroncards::Profile::retrieve('profile_id', 22, 'creator', 'Patroncards') called at /home/vagrant/kohaclone/patroncards/edit-template.pl line 78
Comment 1 Jonathan Druart 2019-11-19 09:59:05 UTC
This is even worst with strict_sql_modes turned on, the creation of a new template is impossible:

DBD::mysql::st execute failed: Incorrect integer value: '' for column 'profile_id' at row 1 [for Statement "INSERT INTO creator_templates (`creator`, `label_height`, `top_margin`, `units`, `col_gap`, `row_gap`,
`left_text_margin`, `rows`, `page_height`, `template_code`, `top_text_margin`, `label_width`, `left_margin`, `cols`, `profile_id`, `page_width`, `template_desc`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);" with ParamValues: 0='Patroncards', 1="0", 2="0", 3="POINT", 4="0", 5="0", 6=0, 7="0", 8="0", 9="DEFAULT TEMPLATE", 10=0, 11="0", 12="0", 13="0", 14='', 15="0", 16="Default description"] at /kohadevbox/koha/C4/Creators/Template.pm line 199.
Database returned the following error: Incorrect integer value: '' for column 'profile_id' at row 1 at /kohadevbox/koha/C4/Creators/Template.pm line 201.

There is a logic issue in the controller, the printer profile list is not passed to the template (only passed when editing).
Comment 2 Chris Nighswonger 2019-11-19 12:52:39 UTC
(In reply to Jonathan Druart from comment #1)
> This is even worst with strict_sql_modes turned on, the creation of a new
> template is impossible:
> 
> DBD::mysql::st execute failed: Incorrect integer value: '' for column
> 'profile_id' ... at
> /kohadevbox/koha/C4/Creators/Template.pm line 199.
> Database returned the following error: Incorrect integer value: '' for
> column 'profile_id' at row 1 at /kohadevbox/koha/C4/Creators/Template.pm
> line 201.
> 
> There is a logic issue in the controller, the printer profile list is not
> passed to the template (only passed when editing).

The default profile_id should be 0: http://tinyurl.com/smoh5g6

Which is overwritten here: http://tinyurl.com/s2pj4cs

Probably changing

profile_id      => scalar $cgi->param('profile_id'),

to

profile_id      => scalar $cgi->param('profile_id') || 0,

would fix the acute pain.

I suspect that there are many such issues lurking in the label/patroncard code unfortunately.
Comment 3 Jonathan Druart 2019-11-19 13:19:40 UTC
There is not printers_profile.profile_id in DB, so I am expecting an error as well.

Is there a good reason to not display the list of available profiles on adding?
Comment 4 Jonathan Druart 2019-11-19 13:20:12 UTC
There is no printers_profile.profile_id == 0 in DB, so I am expecting an error as well.

Is there a good reason to not display the list of available profiles on adding?
Comment 5 Chris Nighswonger 2019-11-19 13:27:32 UTC
(In reply to Jonathan Druart from comment #4)
> There is no printers_profile.profile_id == 0 in DB, so I am expecting an
> error as well.
> 
> Is there a good reason to not display the list of available profiles on
> adding?

It should: http://tinyurl.com/rkfw9fx

And on further review of that code block, the profile_id should be set to 0 there.

Something else must be failing along the way. Maybe in your instance its never dropping into that else block? If that's the case, I wonder where it goes? What is $op in your instance?
Comment 6 Chris Nighswonger 2019-11-19 13:28:52 UTC
(In reply to Chris Nighswonger from comment #5)
> (In reply to Jonathan Druart from comment #4)
> > There is no printers_profile.profile_id == 0 in DB, so I am expecting an
> > error as well.
> > 
> > Is there a good reason to not display the list of available profiles on
> > adding?
> 
> It should: http://tinyurl.com/rkfw9fx
> 
> And on further review of that code block, the profile_id should be set to 0
> there.
> 
> Something else must be failing along the way. Maybe in your instance its
> never dropping into that else block? If that's the case, I wonder where it
> goes? What is $op in your instance?

Better yet, what is the value of $template_id in your instance? Maybe there is some corrupted data that the script is choking on?
Comment 7 Jonathan Druart 2019-11-19 13:48:34 UTC
(In reply to Chris Nighswonger from comment #5)
> (In reply to Jonathan Druart from comment #4)
> > There is no printers_profile.profile_id == 0 in DB, so I am expecting an
> > error as well.
> > 
> > Is there a good reason to not display the list of available profiles on
> > adding?
> 
> It should: http://tinyurl.com/rkfw9fx

We are in patroncards/edit-profile.pl, which does not have this else{} part.
Comment 8 Chris Nighswonger 2019-11-19 13:52:40 UTC
(In reply to Jonathan Druart from comment #7)
> (In reply to Chris Nighswonger from comment #5)
> > (In reply to Jonathan Druart from comment #4)
> > > There is no printers_profile.profile_id == 0 in DB, so I am expecting an
> > > error as well.
> > > 
> > > Is there a good reason to not display the list of available profiles on
> > > adding?
> > 
> > It should: http://tinyurl.com/rkfw9fx
> 
> We are in patroncards/edit-profile.pl, which does not have this else{} part.

edit-profile.pl or edit-template.pl?

> This is even worst with strict_sql_modes turned on, the creation of a new
> template is impossible:

...

> There is a logic issue in the controller, the printer profile list is not
> passed to the template (only passed when editing).

http://tinyurl.com/t9zksc2
Comment 9 Jonathan Druart 2019-11-19 14:18:37 UTC
edit-template, sorry!

So basically, /cgi-bin/koha/patroncards/edit-template.pl?op=new
displays:
  https://snipboard.io/HCSgBE.jpg

See the "Click here to define a printer profile", even if printer profiles exist (this is IMO a bug).

Then save => It's not saved and we get the SQL error.

Given the code you pointed it to me, a profile is created if none is passed. Are we expecting it to be created with a profile_id=0?
What on the second template we will add? We created another profile_id=0?
Comment 10 Chris Nighswonger 2019-11-19 14:29:06 UTC
(In reply to Jonathan Druart from comment #9)
> edit-template, sorry!
> 
> So basically, /cgi-bin/koha/patroncards/edit-template.pl?op=new
> displays:
>   https://snipboard.io/HCSgBE.jpg
> 
> See the "Click here to define a printer profile", even if printer profiles
> exist (this is IMO a bug).

I tend to agree.

> 
> Then save => It's not saved and we get the SQL error.
> 
> Given the code you pointed it to me, a profile is created if none is passed.
> Are we expecting it to be created with a profile_id=0?
> What on the second template we will add? We created another profile_id=0?

No.

When a new template is created with no profile_id passed along, the profile_id is set to 0: http://tinyurl.com/smoh5g6

Ah ha! Here is the offending line: http://tinyurl.com/qurdjnc

It should be thus:

my @params = (      profile_id      => scalar $cgi->param('profile_id') || 0,

Only we need to be sure that the value of profile_id is truly numeric and not just null. Perhaps it may need to be quoted. Field constraints disallow null values and '' is just that, of course.
Comment 11 Chris Nighswonger 2019-11-19 14:32:14 UTC
I would guess the same issue exists in labels: http://tinyurl.com/s2pj4cs
Comment 12 Chris Nighswonger 2019-11-19 14:47:35 UTC
(In reply to Jonathan Druart from comment #9)
> edit-template, sorry!
> 
> So basically, /cgi-bin/koha/patroncards/edit-template.pl?op=new
> displays:
>   https://snipboard.io/HCSgBE.jpg
> 
> See the "Click here to define a printer profile", even if printer profiles
> exist (this is IMO a bug).

This could probably be fixed by doing something similar to this:

http://tinyurl.com/rmhmmw8

in here:

http://tinyurl.com/tshysa5

Adjusting the code for the fact that there is not yet a template_id, of course.

I'll be away for a few hours now.
Comment 13 Chris Nighswonger 2019-11-19 18:00:13 UTC
(In reply to Jonathan Druart from comment #0)
> To recreate:
> - Go to Home › Tools › Patron card creator › Templates 
> - New > Card template
> - Save
> - Edit
> - Save
> 
> =>
> Can't bless non-reference value at
> /home/vagrant/kohaclone/C4/Creators/Profile.pm line 89
>         C4::Creators::Profile::retrieve('C4::Patroncards::Profile',
> 'profile_id', 22, 'creator', 'Patroncards') called at
> /home/vagrant/kohaclone/C4/Patroncards/Profile.pm line 29                   
> C4::Patroncards::Profile::retrieve('profile_id', 22, 'creator',
> 'Patroncards') called at
> /home/vagrant/kohaclone/patroncards/edit-template.pl line 78

Just reading back over this: Does your installation have a profile with a profile_id == 22?

It seems that the problem described in the first comment could be different from the one described in the second second.
Comment 14 Jonathan Druart 2019-11-19 19:34:10 UTC
It has a printers_profile.profile_id = 22, but I think here we are talking about creator_templates.profile_id

MySQL [koha_kohadev]> select template_id, profile_id from creator_templates;
+-------------+------------+
| template_id | profile_id |
+-------------+------------+
|          22 |          0 |
|          24 |          0 |
|           1 |          1 |
|           7 |         13 |
|          12 |         14 |
|          23 |         16 |
+-------------+------------+
Comment 15 Chris Nighswonger 2019-11-19 19:43:31 UTC
(In reply to Jonathan Druart from comment #14)
> It has a printers_profile.profile_id = 22, but I think here we are talking
> about creator_templates.profile_id
> 
> MySQL [koha_kohadev]> select template_id, profile_id from creator_templates;

The error occurs on attempting to execute the following on your system in the script:

SELECT * FROM printers_profile WHERE profile_id = 22 AND creator = 'Patroncards';

What does that say in the client?
Comment 16 Chris Nighswonger 2019-11-19 19:45:44 UTC
Just to be clear: I think we are encountering different issues in the description and comment #1.
Comment 17 Jonathan Druart 2019-11-25 12:17:02 UTC
(In reply to Chris Nighswonger from comment #16)
> Just to be clear: I think we are encountering different issues in the
> description and comment #1.

Yes of course, it is what I said in comment #1.

If you have the strict_sql_modes turned on it explodes on creating the template.


(In reply to Chris Nighswonger from comment #15)
> (In reply to Jonathan Druart from comment #14)
> > It has a printers_profile.profile_id = 22, but I think here we are talking
> > about creator_templates.profile_id
> > 
> > MySQL [koha_kohadev]> select template_id, profile_id from creator_templates;
> 
> The error occurs on attempting to execute the following on your system in
> the script:
> 
> SELECT * FROM printers_profile WHERE profile_id = 22 AND creator =
> 'Patroncards';
> 
> What does that say in the client?

0. I am using the fresh install, with all the sample data.
1. Turning off strict_sql_modes
2. Go to Home › Tools › Patron card creator › Templates 
3. New > Card template
4. Save
5. Edit
6. Save

Can't bless non-reference value at /kohadevbox/koha/C4/Creators/Profile.pm line 89                                                                                                                                 
        C4::Creators::Profile::retrieve('C4::Patroncards::Profile', 'profile_id', 22, 'creator', 'Patroncards') called at /kohadevbox/koha/C4/Patroncards/Profile.pm line 29                                       
        C4::Patroncards::Profile::retrieve('profile_id', 22, 'creator', 'Patroncards') called at /kohadevbox/koha/patroncards/edit-template.pl line 78
        eval {...} at /kohadevbox/koha/patroncards/edit-template.pl line 2


MariaDB [koha_kohadev]> SELECT * FROM printers_profile WHERE profile_id = 22 AND creator = 'Patroncards';
Empty set (0.00 sec)
Comment 18 Jonathan Druart 2019-11-25 12:19:09 UTC
On "Edit" I am on /patroncards/edit-template.pl?op=edit&element_id=24

https://snipboard.io/Qhk87I.jpg

"Library Laser/Tray 3" has a profile_id=22
Comment 19 Chris Nighswonger 2019-11-25 13:52:32 UTC
(In reply to Jonathan Druart from comment #17)
> (In reply to Chris Nighswonger from comment #16)
> > Just to be clear: I think we are encountering different issues in the
> > description and comment #1.
> 
> Yes of course, it is what I said in comment #1.
> 
> If you have the strict_sql_modes turned on it explodes on creating the
> template.
> 

Let's open a separate bug for the second issue you mention. The strict sql issue.

> 
> (In reply to Chris Nighswonger from comment #15)
> > (In reply to Jonathan Druart from comment #14)
> > > It has a printers_profile.profile_id = 22, but I think here we are talking
> > > about creator_templates.profile_id
> > > 
> > > MySQL [koha_kohadev]> select template_id, profile_id from creator_templates;
> > 
> > The error occurs on attempting to execute the following on your system in
> > the script:
> > 
> > SELECT * FROM printers_profile WHERE profile_id = 22 AND creator =
> > 'Patroncards';
> > 
> > What does that say in the client?
> 
> 0. I am using the fresh install, with all the sample data.
> 1. Turning off strict_sql_modes
> 2. Go to Home › Tools › Patron card creator › Templates 
> 3. New > Card template
> 4. Save
> 5. Edit
> 6. Save
> 
> Can't bless non-reference value at /kohadevbox/koha/C4/Creators/Profile.pm
> line 89                                                                     
> 
>         C4::Creators::Profile::retrieve('C4::Patroncards::Profile',
> 'profile_id', 22, 'creator', 'Patroncards') called at
> /kohadevbox/koha/C4/Patroncards/Profile.pm line 29                          
> 
>         C4::Patroncards::Profile::retrieve('profile_id', 22, 'creator',
> 'Patroncards') called at /kohadevbox/koha/patroncards/edit-template.pl line
> 78
>         eval {...} at /kohadevbox/koha/patroncards/edit-template.pl line 2
> 
> 
> MariaDB [koha_kohadev]> SELECT * FROM printers_profile WHERE profile_id = 22
> AND creator = 'Patroncards';
> Empty set (0.00 sec)

Forgive me as I do not have a test installation setup nor the time to get one up  and running:

What does 'SELECT template_id, profile_id, template_desc, creator FROM creator_templates;' say?

I think I know what is causing this.
Comment 20 Jonathan Druart 2019-11-25 14:22:09 UTC
MariaDB [koha_kohadev]> SELECT template_id, profile_id, template_desc, creator FROM creator_templates;
+-------------+------------+------------------------------------------------------------+-------------+
| template_id | profile_id | template_desc                                              | creator     |
+-------------+------------+------------------------------------------------------------+-------------+
|           1 |          1 | 3 columns, 10 rows of labels                               | Labels      |
|           7 |         13 | 1" X 1.5" Spine Label | Setup for up to four lines of text | Labels      |
|          12 |         14 | 1" X 1.5" Spine Label | Setup for five lines of text       | Labels      |
|          22 |          0 | Default description                                        | Labels      |
|          23 |         16 | A template for home brewed patron card forms               | Patroncards |
|          24 |          0 | Default description                                        | Patroncards |
+-------------+------------+------------------------------------------------------------+-------------+
6 rows in set (0.00 sec)
Comment 21 Chris Nighswonger 2019-11-25 14:29:43 UTC
What language sample data are you using on this test set?

Side note: The sample data for labels/patroncards among various languages appears to vary tremendously and probably erroneously.
Comment 22 Jonathan Druart 2019-11-25 14:41:45 UTC
(In reply to Chris Nighswonger from comment #21)
> What language sample data are you using on this test set?
> 
> Side note: The sample data for labels/patroncards among various languages
> appears to vary tremendously and probably erroneously.

I am using a 'classic' install, 'en'.
Comment 23 Chris Nighswonger 2019-11-26 14:38:38 UTC
I'm working on using Bywater's sandbox script to set up a test bed. Once that's up and running, I'll work through this bug.
Comment 24 Chris Nighswonger 2019-12-03 18:14:21 UTC
Created attachment 95981 [details] [review]
Bug 24001: Cannot edit card template

Change hardcoded default value of profile_id to 0 rather than null.

Signed-off-by: Chris Nighswonger <cnighswonger@foundations.edu>
Comment 25 Chris Nighswonger 2019-12-03 18:18:32 UTC
Test plan:

1. Using the fresh install, with all the sample data.
2. Go to Home › Tools › Patron card creator › Templates 
3. New > Card template
4. Save
5. Edit
6. Save

Note either of the two errors in the error log.

Apply the attached patch.

1. Go to Home › Tools › Patron card creator › Templates
2. Select the previously created template
3. Delete it
4. New > Card template
5. Save
6. Edit
7. Save

Note the absence of either of the two errors in error log.
Comment 26 Chris Nighswonger 2019-12-03 18:32:48 UTC
This actually fixes both issues described in this bug.

To test this, re-run the above procedure with strict_sql_modes set to the opposite value.
Comment 27 Jonathan Druart 2019-12-05 15:42:19 UTC
The patch fixes the creation with strict_sql_modes on (comment 1), but not the edition from comment 0

Can't bless non-reference value at /kohadevbox/koha/C4/Creators/Profile.pm line 89
Comment 28 Rinrada Wongsaichua 2020-02-11 15:36:10 UTC
Error when saving Patron card Template: 
Can't bless non-reference value at /home/vagrant/kohaclone/C4/Creators/Profile.pm line 89

Can be fixed by add this one line into /usr/share/koha/intranet/cgi-bin/patroncards/edit-template.pl

52    $profile_list = get_all_profiles({ fields => [ qw( profile_id printer_name paper_bin ) ], filters => {template_id => [ $template_id, '' ]} } );
+++   push @$profile_list, {paper_bin => 'N/A', profile_id => 0, printer_name => 'No Profile'};
Comment 29 Jonathan Druart 2020-02-11 15:39:32 UTC
(In reply to Rinrada Wongsaichua from comment #28)
> Error when saving Patron card Template: 
> Can't bless non-reference value at
> /home/vagrant/kohaclone/C4/Creators/Profile.pm line 89
> 
> Can be fixed by add this one line into
> /usr/share/koha/intranet/cgi-bin/patroncards/edit-template.pl
> 
> 52    $profile_list = get_all_profiles({ fields => [ qw( profile_id
> printer_name paper_bin ) ], filters => {template_id => [ $template_id, '' ]}
> } );
> +++   push @$profile_list, {paper_bin => 'N/A', profile_id => 0,
> printer_name => 'No Profile'};

Can you please provide a patch?
Comment 30 Rinrada Wongsaichua 2020-02-11 16:21:08 UTC
(In reply to Jonathan Druart from comment #29)
> (In reply to Rinrada Wongsaichua from comment #28)
> > Error when saving Patron card Template: 
> > Can't bless non-reference value at
> > /home/vagrant/kohaclone/C4/Creators/Profile.pm line 89
> > 
> > Can be fixed by add this one line into
> > /usr/share/koha/intranet/cgi-bin/patroncards/edit-template.pl
> > 
> > 52    $profile_list = get_all_profiles({ fields => [ qw( profile_id
> > printer_name paper_bin ) ], filters => {template_id => [ $template_id, '' ]}
> > } );
> > +++   push @$profile_list, {paper_bin => 'N/A', profile_id => 0,
> > printer_name => 'No Profile'};
> 
> Can you please provide a patch?

Sorry I'm new here(In reply to Jonathan Druart from comment #29)
> (In reply to Rinrada Wongsaichua from comment #28)
> > Error when saving Patron card Template: 
> > Can't bless non-reference value at
> > /home/vagrant/kohaclone/C4/Creators/Profile.pm line 89
> > 
> > Can be fixed by add this one line into
> > /usr/share/koha/intranet/cgi-bin/patroncards/edit-template.pl
> > 
> > 52    $profile_list = get_all_profiles({ fields => [ qw( profile_id
> > printer_name paper_bin ) ], filters => {template_id => [ $template_id, '' ]}
> > } );
> > +++   push @$profile_list, {paper_bin => 'N/A', profile_id => 0,
> > printer_name => 'No Profile'};
> 
> Can you please provide a patch?

I'm sorry I'm new for this site, really don't know how to attach patch or create one

Basically you just need to add this line into edit-template.pl then issue resolved
You'll now able to save patron card template without any error

--- /usr/share/koha/intranet/cgi-bin/patroncards/edit-template.pl

on line 52    $profile_list = get_all_profiles({ fields => [ qw( profile_id printer_name paper_bin ) ], filters => {template_id => [ $template_id, '' ]} } );
++++++++++    push @$profile_list, {paper_bin => 'N/A', profile_id => 0, printer_name => 'No Profile'};
Comment 31 Jonathan Druart 2020-02-11 16:30:15 UTC
Please do not change the status to "resolved". It is marked resolved once we have a patch pushed into master.
Comment 32 Rinrada Wongsaichua 2020-02-11 16:36:07 UTC
okay I don't know how it works 
But I just wanted to share solution that work for me
I've tested on my server and issue has been resolved
Comment 33 Rinrada Wongsaichua 2020-02-11 17:17:29 UTC
Created attachment 98722 [details] [review]
[PATCH] Bug 24001: Cannot edit card template
Comment 34 Jonathan Druart 2020-02-18 10:02:02 UTC
Created attachment 99164 [details] [review]
Bug 24001: Fix patron card template edition

Error when saving Patron card Template:
Can't bless non-reference value at
/home/vagrant/kohaclone/C4/Creators/Profile.pm line 89

Can be fixed by add this one line into
/usr/share/koha/intranet/cgi-bin/patroncards/edit-template.pl
Comment 35 Jonathan Druart 2020-02-18 10:04:03 UTC
Hello Rinrada,

I have attached a file that has the correct format (patch).
However I am not sure this is the correct way to fix the issue.

Chris, can we get your opinion on it?
Comment 36 Rinrada Wongsaichua 2020-02-18 16:06:43 UTC
(In reply to Jonathan Druart from comment #35)
> Hello Rinrada,
> 
> I have attached a file that has the correct format (patch).
> However I am not sure this is the correct way to fix the issue.
> 
> Chris, can we get your opinion on it?

Hi Jonathan,

every time I edit template of patroncards which has no profile_id attached to template
Profile will display first printer name from the selector list even if profile_id==0

Tested edit on template of labels that has no profile_id attached (profile_id==0)
It will display 'Profile: No Profile/N/A' and able to save successfully no error

Checked label-edit-template.pl and found this line 

>> push @$profile_list, {paper_bin => 'N/A', profile_id => 0, printer_name => 'No Profile'};

which only exist in label-edit-template.pl but does not exist in edit-template.pl

Checked database and noticed that both patroncards and labels stored Printer profiles in the same table (printers_profile table) and identify by creator field


Hopefully my investigation will help you guys on this case come how
Comment 37 Caroline Cyr La Rose 2020-06-17 16:26:41 UTC
I tested the patchset and it works. When you edit a card template, there is no more error and the profile is set to No profile/NA.

However, the drop-down menu for the profiles still gives me the possibility to choose a printer profile that is not part of the patron cards creator but the label creator. If I try to select that profile, it gives me an error, which is expected, but the choice should not be there in the first place.

The drop down menu should be limited to printer profiles in the patron card creator (plus the No profile choice).
Comment 38 Blou 2020-06-30 16:55:08 UTC
Created attachment 106434 [details] [review]
Bug 24001: Fix patron card template edition

Error when saving Patron card Template:
Can't bless non-reference value at
/home/vagrant/kohaclone/C4/Creators/Profile.pm line 89

This is caused by the profile dropdown offering invalid choices and is
fixed by adding a filter to limit options to creator = 'Patroncards'.
The UI already handles the case where no valid profile is avaiable.
Comment 39 Alexis Ripetti 2020-09-08 19:12:14 UTC
Created attachment 109764 [details] [review]
Bug 24001: Fix patron card template edition

Error when saving Patron card Template:
Can't bless non-reference value at
/home/vagrant/kohaclone/C4/Creators/Profile.pm line 89

This is caused by the profile dropdown offering invalid choices and is
fixed by adding a filter to limit options to creator = 'Patroncards'.
The UI already handles the case where no valid profile is avaiable.

Signed-off-by: Alexis Ripetti <alexis.ripetti@inLibro.com>
Comment 40 David Nind 2020-10-03 07:23:24 UTC
Apologies for the rather long comment, and for marking as "Failed QA".

TLDR;
- the patch works, however there is a problem with the printer profile drop down list - it takes you to the new printer profile page
- you can't create a new printer profile (for both the patron card creator and the label creator tools) - this should possibly be another bug
- it looks like this hasn't worked for several versions

Before applying the patch
=========================

The card template is not created and you are returned to the list of currently available templates. These error messages are generated in /var/log/koha/kohadev/plack-intranet-error.log:

1 [2020/10/03 06:08:27] [WARN] DBD::mysql::st execute failed: Incorrect integer value: '' for column 'profile_id' at row 1 [for Statem    ent "INSERT INTO creator_templates (`template_code`, `label_width`, `top_margin`, `col_gap`, `template_desc`, `row_gap`, `rows`, `pa    ge_width`, `cols`, `label_height`, `units`, `top_text_margin`, `left_margin`, `left_text_margin`, `profile_id`, `creator`, `page_hei    ght`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);" with ParamValues: 0="A DEFAULT TEMPLATE", 1="0", 2="0", 3="0", 4="A Default descr    iption", 5="0", 6="0", 7="0", 8="0", 9="0", 10="POINT", 11=0, 12="0", 13=0, 14='', 15='Patroncards', 16="0"] at /kohadevbox/koha/C4/    Creators/Template.pm line 199.
2 [2020/10/03 06:08:27] [WARN] Database returned the following error: Incorrect integer value: '' for column 'profile_id' at row 1 at     /kohadevbox/koha/C4/Creators/Template.pm line 201.
3 [2020/10/03 06:08:28] [WARN] CGI::param called in list context from /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/en/includes/patron    cards-errors.inc line 57, this can lead to vulnerabilities. See the warning in "Fetching the value or values of a single named param    eter" at /usr/share/perl5/CGI.pm line 412.

If you try to create a printer profile (New > Printer profile) the printer profile is not created - you are returned to the list of current available templates. These error messages are generated in /var/log/koha/kohadev/plack-intranet-error.log:

4 [2020/10/03 06:10:57] [WARN] DBD::mysql::st execute failed: Incorrect integer value: '' for column 'template_id' at row 1 [for State    ment "INSERT INTO printers_profile (creep_vert, offset_horz, units, printer_name, creator, template_id, offset_vert, paper_bin, cree    p_horz) VALUES (?,?,?,?,?,?,?,?,?);" with ParamValues: 0="0", 1="0", 2="POINT", 3="ABC", 4='Patroncards', 5='', 6="0", 7="2", 8="0"]     at /kohadevbox/koha/C4/Creators/Profile.pm line 162.
5 [2020/10/03 06:10:57] [WARN] Database returned the following error on attempted INSERT: Incorrect integer value: '' for column 'temp    late_id' at row 1 at /kohadevbox/koha/C4/Creators/Profile.pm line 164.

After applying the patch
========================

After applying the patch and adding a card template the card template is created, so that fixes that issue!

However, there is this error message in /var/log/koha/kohadev/plack-intranet-error.log:

[2020/10/03 06:15:59] [WARN] CGI::param called in list context from /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/en/includes/patron    cards-errors.inc line 57, this can lead to vulnerabilities. See the warning in "Fetching the value or values of a single named param    eter" at /usr/share/perl5/CGI.pm line 412.

On the create patron card template page if you click on "Click here to define a printer profile.", you are taken to the create printer profile screen. I'm not sure what is expected here, but I expect it should be a drop down list of printer profiles like for the label creator tool (as per Caroline's comment #37).

If you try to create a printer profile you get the same behaviour as before the patch was applied.

Other notes:
- Tested using koha-testing-docker and started with ku.
- Using the label creator tool, you get the same error message when you try to create a printer profile for the patron card creator.

Error messages for Koha 20.05.x, Koha 19.11.x
=============================================

You get these error messages in Koha 20.05.x, 19.11.x and 19.05.x

Create a patron card template - error message in /var/log/koha/kohadev/plack-error.log:

7 DBD::mysql::st execute failed: Incorrect integer value: '' for column 'profile_id' at row 1 [for Statement "INSERT INTO creator_templates (`row_gap`, `units`, `temp    late_code`, `page_height`, `left_text_margin`, `page_width`, `profile_id`, `top_text_margin`, `creator`, `label_width`, `template_desc`, `left_margin`, `rows`, `col    s`, `top_margin`, `col_gap`, `label_height`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);" with ParamValues: 0="0", 1="POINT", 2="A DEFAULT TEMPLATE", 3="0", 4=0, 5=    "0", 6='', 7=0, 8='Patroncards', 9="0", 10="A default description", 11="0", 12="0", 13="0", 14="0", 15="0", 16="0"] at /kohadevbox/koha/C4/Creators/Template.pm line     199.
8 Database returned the following error: Incorrect integer value: '' for column 'profile_id' at row 1 at /kohadevbox/koha/C4/Creators/Template.pm line 201.
9 CGI::param called in list context from /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/en/includes/patroncards-errors.inc line 57, this can lead to vulnerabilities. S    ee the warning in "Fetching the value or values of a single named parameter" at /usr/share/perl5/CGI.pm line 412.

Create a printer profile - error message in /var/log/koha/kohadev/plack-error.log::

10 DBD::mysql::st execute failed: Incorrect integer value: '' for column 'template_id' at row 1 [for Statement "INSERT INTO printers_profile (creator, template_id, off    set_horz, units, printer_name, creep_horz, creep_vert, offset_vert, paper_bin) VALUES (?,?,?,?,?,?,?,?,?);" with ParamValues: 0='Patroncards', 1='', 2="0", 3="POINT    ", 4="ABZ", 5="0", 6="0", 7="0", 8="9"] at /kohadevbox/koha/C4/Creators/Profile.pm line 162.
11 Database returned the following error on attempted INSERT: Incorrect integer value: '' for column 'template_id' at row 1 at /kohadevbox/koha/C4/Creators/Profile.pm     line 164.

Create a printer profile for the label creator tool - error message in /var/log/koha/kohadev/plack-error.log:

12 profile_id is currently undefined. at /kohadevbox/koha/C4/Creators/Profile.pm line 184.
13 DBD::mysql::st execute failed: Incorrect integer value: '' for column 'template_id' at row 1 [for Statement "INSERT INTO printers_profile (units, printer_name, temp    late_id, creator, offset_horz, offset_vert, paper_bin, creep_horz, creep_vert) VALUES (?,?,?,?,?,?,?,?,?);" with ParamValues: 0="POINT", 1="ABZ", 2='', 3='Labels',     4=0, 5=0, 6="1", 7=0, 8=0] at /kohadevbox/koha/C4/Creators/Profile.pm line 162.
14 Database returned the following error on attempted INSERT: Incorrect integer value: '' for column 'template_id' at row 1 at /kohadevbox/koha/C4/Creators/Profile.pm     line 164.
Comment 41 Jonathan Druart 2021-01-27 08:59:09 UTC
*** Bug 27517 has been marked as a duplicate of this bug. ***
Comment 42 Martin Renvoize 2021-03-30 15:17:16 UTC
Still able to work on this Blou?
Comment 43 Blou 2021-03-30 16:00:29 UTC
I suppose we could extend the patch to catch all cases where profile_id is set to '' instead of 0

The errors comes from save(), which seems called by label-edit-template.pl and patroncards/edit-template.pl which are very loose with their assignments of profile_id.

But beside that, you'll have to be specific.  We coded (and use) this patch in its simplest form, to avoid the problems.  But we're not rearchitecturing the underlying issues.
Comment 44 The Minh Luong 2022-03-04 14:50:06 UTC
Hi. 
I have followed the steps of comment 40 and I can't reproduce the problem.

Here is what i did: 
After applying the patch: 

I attempt to create a new card template. The card template is created. However, I don't see any errors in my plack-intranet-error.log file. I also checked other logs and no error are displayed. 

I also tried to create a printer profile, as mentioned in the comment. The profile is created and I still can't see any of the errors in the log files.
Comment 45 Nick Clemens 2022-03-04 16:27:13 UTC
Created attachment 131381 [details] [review]
Bug 24001: Fix Card template/rpinter profile creation and edit

This patch adjusts the template/profiles to use the default of '0'
This should probably be NULL, and the columns foreign keys, this code
could use a further rewrite, but this should fix a long standing bug

To test:
 1 - Using the fresh install, with all the sample data.
 2 - Go to Home › Tools › Patron card creator › Templates
 3 - New > Card template
 4 - Save
 5 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'profile_id' at row 1
 6 - Edit an existing template
 7 - Save
 8 - Error: Can't bless non-reference value at /kohadevbox/koha/C4/Creators/Profile.pm line 89
 9 - Create a new 'Printer profile'
10 - Save
11 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'template_id' at row 1
12 - Apply the attached patch.
13 - Verify you can create a new 'Card template' and 'Printer profile' with no errors
14 - Verify you can edit and save both of the newly created objects above
Comment 46 The Minh Luong 2022-03-08 16:59:00 UTC
Created attachment 131494 [details] [review]
Bug 24001: Fix patron card template edition

Error when saving Patron card Template:
Can't bless non-reference value at
/home/vagrant/kohaclone/C4/Creators/Profile.pm line 89

This is caused by the profile dropdown offering invalid choices and is
fixed by adding a filter to limit options to creator = 'Patroncards'.
The UI already handles the case where no valid profile is avaiable.

Signed-off-by: Alexis Ripetti <alexis.ripetti@inLibro.com>
Comment 47 The Minh Luong 2022-03-08 16:59:05 UTC
Created attachment 131495 [details] [review]
Bug 24001: Fix Card template/rpinter profile creation and edit

This patch adjusts the template/profiles to use the default of '0'
This should probably be NULL, and the columns foreign keys, this code
could use a further rewrite, but this should fix a long standing bug

To test:
 1 - Using the fresh install, with all the sample data.
 2 - Go to Home › Tools › Patron card creator › Templates
 3 - New > Card template
 4 - Save
 5 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'profile_id' at row 1
 6 - Edit an existing template
 7 - Save
 8 - Error: Can't bless non-reference value at /kohadevbox/koha/C4/Creators/Profile.pm line 89
 9 - Create a new 'Printer profile'
10 - Save
11 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'template_id' at row 1
12 - Apply the attached patch.
13 - Verify you can create a new 'Card template' and 'Printer profile' with no errors
14 - Verify you can edit and save both of the newly created objects above
Comment 48 David Nind 2022-04-27 14:47:14 UTC
Created attachment 134074 [details] [review]
Bug 24001: Fix patron card template edition

Error when saving Patron card Template:
Can't bless non-reference value at
/home/vagrant/kohaclone/C4/Creators/Profile.pm line 89

This is caused by the profile dropdown offering invalid choices and is
fixed by adding a filter to limit options to creator = 'Patroncards'.
The UI already handles the case where no valid profile is avaiable.

Signed-off-by: Alexis Ripetti <alexis.ripetti@inLibro.com>

Signed-off-by: David Nind <david@davidnind.com>
Comment 49 David Nind 2022-04-27 14:47:20 UTC
Created attachment 134075 [details] [review]
Bug 24001: Fix Card template/rpinter profile creation and edit

This patch adjusts the template/profiles to use the default of '0'
This should probably be NULL, and the columns foreign keys, this code
could use a further rewrite, but this should fix a long standing bug

To test:
 1 - Using the fresh install, with all the sample data.
 2 - Go to Home › Tools › Patron card creator › Templates
 3 - New > Card template
 4 - Save
 5 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'profile_id' at row 1
 6 - Edit an existing template
 7 - Save
 8 - Error: Can't bless non-reference value at /kohadevbox/koha/C4/Creators/Profile.pm line 89
 9 - Create a new 'Printer profile'
10 - Save
11 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'template_id' at row 1
12 - Apply the attached patch.
13 - Verify you can create a new 'Card template' and 'Printer profile' with no errors
14 - Verify you can edit and save both of the newly created objects above

Signed-off-by: David Nind <david@davidnind.com>
Comment 50 Martin Renvoize 2022-04-27 15:21:44 UTC
Created attachment 134077 [details] [review]
Bug 24001: Fix patron card template edition

Error when saving Patron card Template:
Can't bless non-reference value at
/home/vagrant/kohaclone/C4/Creators/Profile.pm line 89

This is caused by the profile dropdown offering invalid choices and is
fixed by adding a filter to limit options to creator = 'Patroncards'.
The UI already handles the case where no valid profile is avaiable.

Signed-off-by: Alexis Ripetti <alexis.ripetti@inLibro.com>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 51 Martin Renvoize 2022-04-27 15:21:49 UTC
Created attachment 134078 [details] [review]
Bug 24001: Fix Card template/rpinter profile creation and edit

This patch adjusts the template/profiles to use the default of '0'
This should probably be NULL, and the columns foreign keys, this code
could use a further rewrite, but this should fix a long standing bug

To test:
 1 - Using the fresh install, with all the sample data.
 2 - Go to Home › Tools › Patron card creator › Templates
 3 - New > Card template
 4 - Save
 5 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'profile_id' at row 1
 6 - Edit an existing template
 7 - Save
 8 - Error: Can't bless non-reference value at /kohadevbox/koha/C4/Creators/Profile.pm line 89
 9 - Create a new 'Printer profile'
10 - Save
11 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'template_id' at row 1
12 - Apply the attached patch.
13 - Verify you can create a new 'Card template' and 'Printer profile' with no errors
14 - Verify you can edit and save both of the newly created objects above

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 52 Martin Renvoize 2022-04-27 15:22:49 UTC
Looking good and fixes the issue.. no QA script highlights so Passing QA
Comment 53 Katrin Fischer 2022-04-27 15:24:48 UTC
Created attachment 134080 [details] [review]
Bug 24001: Fix patron card template edition

Error when saving Patron card Template:
Can't bless non-reference value at
/home/vagrant/kohaclone/C4/Creators/Profile.pm line 89

This is caused by the profile dropdown offering invalid choices and is
fixed by adding a filter to limit options to creator = 'Patroncards'.
The UI already handles the case where no valid profile is avaiable.

Signed-off-by: Alexis Ripetti <alexis.ripetti@inLibro.com>

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

https://bugs.koha-community.org/show_bug.cgi?id=30373
Comment 54 Katrin Fischer 2022-04-27 15:24:55 UTC
Created attachment 134081 [details] [review]
Bug 24001: Fix Card template/rpinter profile creation and edit

This patch adjusts the template/profiles to use the default of '0'
This should probably be NULL, and the columns foreign keys, this code
could use a further rewrite, but this should fix a long standing bug

To test:
 1 - Using the fresh install, with all the sample data.
 2 - Go to Home › Tools › Patron card creator › Templates
 3 - New > Card template
 4 - Save
 5 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'profile_id' at row 1
 6 - Edit an existing template
 7 - Save
 8 - Error: Can't bless non-reference value at /kohadevbox/koha/C4/Creators/Profile.pm line 89
 9 - Create a new 'Printer profile'
10 - Save
11 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'template_id' at row 1
12 - Apply the attached patch.
13 - Verify you can create a new 'Card template' and 'Printer profile' with no errors
14 - Verify you can edit and save both of the newly created objects above

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

https://bugs.koha-community.org/show_bug.cgi?id=30373
Comment 55 Katrin Fischer 2022-04-27 15:34:47 UTC
Agreeing with Martin, sorry, we overlapped!

I filed 2 new bugs:

Bug 30629 - <span> in title of patron card creator template needs to be removed
Bug 30631 - Show list of existing printer profiles when creating a new patron card template
Comment 56 Martin Renvoize 2022-04-27 16:14:33 UTC
Created attachment 134124 [details] [review]
Bug 24001: Fix patron card template edition

Error when saving Patron card Template:
Can't bless non-reference value at
/home/vagrant/kohaclone/C4/Creators/Profile.pm line 89

This is caused by the profile dropdown offering invalid choices and is
fixed by adding a filter to limit options to creator = 'Patroncards'.
The UI already handles the case where no valid profile is avaiable.

Signed-off-by: Alexis Ripetti <alexis.ripetti@inLibro.com>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 57 Martin Renvoize 2022-04-27 16:14:38 UTC
Created attachment 134125 [details] [review]
Bug 24001: Fix Card template/rpinter profile creation and edit

This patch adjusts the template/profiles to use the default of '0'
This should probably be NULL, and the columns foreign keys, this code
could use a further rewrite, but this should fix a long standing bug

To test:
 1 - Using the fresh install, with all the sample data.
 2 - Go to Home › Tools › Patron card creator › Templates
 3 - New > Card template
 4 - Save
 5 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'profile_id' at row 1
 6 - Edit an existing template
 7 - Save
 8 - Error: Can't bless non-reference value at /kohadevbox/koha/C4/Creators/Profile.pm line 89
 9 - Create a new 'Printer profile'
10 - Save
11 - Error: DBD::mysql::st execute failed: Incorrect integer value: '' for column 'template_id' at row 1
12 - Apply the attached patch.
13 - Verify you can create a new 'Card template' and 'Printer profile' with no errors
14 - Verify you can edit and save both of the newly created objects above

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 58 Fridolin Somers 2022-04-28 20:50:45 UTC
Pushed to master for 22.05, thanks to everybody involved 🦄
Comment 59 Fridolin Somers 2022-04-29 06:25:48 UTC
Created attachment 134346 [details] [review]
Bug 24001: (follow-up) Fix t_Profile.t
Comment 60 Fridolin Somers 2022-04-29 06:28:51 UTC
Test suite was failing, like :
https://jenkins.koha-community.org/view/master/job/Koha_Master_D10/624/testReport/

Fixed by changing expected values.
Comment 61 Kyle M Hall 2022-05-06 17:48:39 UTC
Pushed to 21.11.x for 21.11.06
Comment 62 Victor Grousset/tuxayo 2022-06-17 03:25:41 UTC
Backported: Pushed to 21.05.x branch for 21.05.16
Comment 63 Martin Renvoize 2022-06-23 13:36:39 UTC
Bugfix with not visual or workflow changes, no documentation updates required.