Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#1936 Make the price field value label field not required #18123

Merged
merged 1 commit into from
Aug 11, 2020

Conversation

seamuslee001
Copy link
Contributor

Overview

This reverses a change made in 5.27 which makes the price field value, label field non required preventing string 'null' from being saved

Before

Field is required

After

Field is not always required

Technical Details

I made sure apiv4 matched apiv3 in that the label is required if your using the API

ping @eileenmcnaughton @KarinG @demeritcowboy

@civibot
Copy link

civibot bot commented Aug 11, 2020

(Standard links)

@civibot civibot bot added the master label Aug 11, 2020
@seamuslee001 seamuslee001 force-pushed the dev_core_1936_alternate branch from b5c3270 to eaa9cb0 Compare August 11, 2020 00:30
@seamuslee001 seamuslee001 changed the base branch from master to 5.29 August 11, 2020 00:31
@civibot civibot bot added 5.29 and removed master labels Aug 11, 2020
@@ -29,6 +29,8 @@ class PriceFieldValueCreationSpecProvider implements Generic\SpecProviderInterfa
public function modifySpec(RequestSpec $spec) {
// Name will be auto-generated from label if not supplied
$spec->getFieldByName('name')->setRequired(FALSE);
// Ensure that label is required this matches v3 API but doesn't match DAO because form fields allow for NULLs
$spec->getFieldByName('label')->setRequired(TRUE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 so I'm inclined to go with it not being required in either api - I think the reason it was required was nasty munging behaviour. If that's hard to deal with I'm OK with apiv4 not matching v3 - as long as v4 is 'right'

(am also OK punting that for master)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea but it seems it has been required in the API since v4.5 e825f02 so it would feel very strange to break that but maybe its ok for v4. Also the JIRA mentioned in that commit looks wrong https://issues.civicrm.org/jira/browse/CRM-14788. I would say keep label required for the moment and can manage in master

@seamuslee001 seamuslee001 force-pushed the dev_core_1936_alternate branch from eaa9cb0 to 99d123a Compare August 11, 2020 01:52
@eileenmcnaughton
Copy link
Contributor

Looks good to me - I'll see what jenkins & @KarinG have to say

@KarinG
Copy link
Contributor

KarinG commented Aug 11, 2020

Hi - my d8civicrm.local is a 5.27.4 at the moment so figured I would try this:

  1. I took https://patch-diff.githubusercontent.com/raw/civicrm/civicrm-core/pull/18123.diffand applied the hunks possible

karins-MBP:civicrm-core sysadmin$ cat 18123.diff |patch -p1
patching file CRM/Core/I18n/SchemaStructure.php
patching file CRM/Price/DAO/PriceFieldValue.php
Hunk #1 FAILED at 6.
Hunk #2 succeeded at 219 (offset -7 lines).
Hunk #3 succeeded at 237 (offset -7 lines).
1 out of 3 hunks FAILED -- saving rejects to file CRM/Price/DAO/PriceFieldValue.php.rej
patching file CRM/Upgrade/Incremental/php/FiveTwentyNine.php
Hunk #1 FAILED at 74.
1 out of 1 hunk FAILED -- saving rejects to file CRM/Upgrade/Incremental/php/FiveTwentyNine.php.rej
patching file Civi/Api4/Service/Spec/Provider/PriceFieldValueCreationSpecProvider.php
patching file tests/phpunit/CRM/Price/BAO/PriceFieldValueTest.php
patching file xml/schema/Price/PriceFieldValue.xml

  1. I took the content in CRM/Upgrade/Incremental/php/FiveTwentyNine.php and merged that function into FiveTwentySeven.php replacing the upgrade function that had already been executed with the new bits and naming it 2

  2. I reset my civicrm_domain.version in the db back to 5.27.3

  3. Then ran the upgrade (figured that was an important part here) - upgrade ran - and was happy:

image

Checking the db -> I still see "null"

image

Ok trying this manually:
mysql> UPDATE civicrm_price_field_value SET label = NULL WHERE label = 'null';
ERROR 1048 (23000): Column 'label' cannot be null

Manually phpMyAdmin will let me change 'null' to NULL

Ok manually changed -> I get (same contribution pages I reproduced the issue on)
image

Back to Configure -> my empty labels have NULL now - removing them.
image

Saving -> DB Constraint violation - ( ! )

Aug 10 20:55:47  [error] $Fatal Error Details = Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => UPDATE  `civicrm_price_field_value`  SET `price_field_id` = 2 , `label` = NULL , `amount` = 5.00 , `weight` = 1 , `is_default` = 0 , `is_active` = 1 , `financial_type_id` = 1 , `visibility_id` = 1   WHERE (  `civicrm_price_field_value`.`id` = 2 )   [nativecode=1048 ** Column 'label' cannot be null]
    [type] => DB_Error
    [user_info] => UPDATE  `civicrm_price_field_value`  SET `price_field_id` = 2 , `label` = NULL , `amount` = 5.00 , `weight` = 1 , `is_default` = 0 , `is_active` = 1 , `financial_type_id` = 1 , `visibility_id` = 1   WHERE (  `civicrm_price_field_value`.`id` = 2 )   [nativecode=1048 ** Column 'label' cannot be null]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="UPDATE  `civicrm_price_field_value`  SET `price_field_id` = 2 , `label` = NULL , `amount` = 5.00 , `weight` = 1 , `is_default` = 0 , `is_active` = 1 , `financial_type_id` = 1 , `visibility_id` = 1   WHERE (  `civicrm_price_field_value`.`id` = 2 )   [nativecode=1048 ** Column 'label' cannot be null]"]
)

So what did we do before -> on a 5.27.3 site - I can't do [simple/clean no labels]
image
image

@seamuslee001
Copy link
Contributor Author

adding merge on pass based on @KarinG testing on another PR and this being an identical copy except for the upgrade step

@seamuslee001 seamuslee001 merged commit e1772c4 into civicrm:5.29 Aug 11, 2020
@seamuslee001 seamuslee001 deleted the dev_core_1936_alternate branch August 11, 2020 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants