yii2 icon indicating copy to clipboard operation
yii2 copied to clipboard

BaseActiveRecord save method - php docs do not state possible throwing of exception

Open mandano opened this issue 1 year ago • 2 comments
trafficstars

What steps will reproduce the problem?

  • go to vendor/yiisoft/yii2/db/BaseActiveRecord.php
  • check [at]throws attribute in php docs
  • check insert() method php docs in ActiveRecord.php,
  • check update() method php docs in BaseActiveRecord.php

What is the expected result?

  • expected to contain [at]throws StaleObjectException, Exception or Throwable as update(), insert() methods could throw these
  • in case save() should not throw an exception, catch needed for update(), insert() methods

What do you get instead?

  • no [at]throws statement stated
  • or missing catch statements in save()

Additional info

Q A
Yii version 2.0.49.4
PHP version
Operating system Linux

save() method - BaseActiveRecord grafik

insert() method - ActiveRecord grafik

update() method - BaseActiveRecord grafik

mandano avatar Jul 26 '24 11:07 mandano

Should be added to phpdoc, indeed. Do you have time for a pull request?

samdark avatar Jul 26 '24 16:07 samdark

Should be added to phpdoc, indeed. Do you have time for a pull request?

hey! i have time for a pr. Btw what do you think about catching the exceptions inside of save(). as otherwise each user of save() needs to create a try catch, which bloats up that user's abstraction layer unnecessarily?

mandano avatar Jul 29 '24 16:07 mandano

for phpdoc see https://github.com/yiisoft/yii2/pull/20146

about catching the exceptions inside of save(): I think this should/can not be done, as exceptions thrown within save() can be (or are) used to handle use cases like https://github.com/yiisoft/yii2/issues/8392 or https://github.com/yiisoft/yii2/issues/20253

handcode avatar Sep 17 '24 13:09 handcode

ok, thank you.

mandano avatar Sep 21 '24 09:09 mandano