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

test: fix forgetting to restore DBDebug value #6115

Merged
merged 5 commits into from
Jun 15, 2022

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jun 13, 2022

Description

  • add disableDBDebug() and enableDBDebug() in DatabaseTestTrait
  • add missing enableDBDebug()
  • refactor

Related #6113

Checklist:

  • Securely signed commits
  • [] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [] Unit testing, with >80% coverage
  • [] User guide updated
  • Conforms to style guide

@kenjis kenjis added the testing Pull requests that changes tests only label Jun 13, 2022
@kenjis
Copy link
Member Author

kenjis commented Jun 13, 2022

All tests failed except MySQL. 😅

There was 1 error:

  1. CodeIgniter\Models\UpdateModelTest::testUpdateWithEntityNoAllowedFields
    ErrorException: pg_query(): Query failed: ERROR: null value in column "email" of relation "db_user" violates not-null constraint
    DETAIL: Failing row contains (5, Jones Martin, null, India, null, null, null).

The failures show changing the behavior according to the DBDebug value is bad practice.

Now in the development environment CI throws Exceptions when DB errors occur,
but in the production environment, CI returns false.
So most devs don't check query return values, and DB errors in the production environment
will be hidden by the configuration.

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

Wow I had no idea we did this in so many cases. Very good consolidation.

Something I would like to see in a future version is a way to "schedule" tear-down actions better - so something that knows it will need to be undone can go ahead and put that in place. It would something akin to this:

    protected function enableDBDebug(): void
    {
        $this->setPrivateProperty($this->db, 'DBDebug', true);

        $this->tearDownMethods[] = 'disableDBDebug`;
    }

@kenjis kenjis merged commit 89223f7 into codeigniter4:develop Jun 15, 2022
@kenjis kenjis deleted the fix-DBDebug-false-tests branch June 15, 2022 00:10
@MGatner
Copy link
Member

MGatner commented Jun 15, 2022

the development environment CI throws Exceptions when DB errors occur,
but in the production environment, CI returns false.

This is pretty bad behavior. Does DBDebug control anything else? Or is it just error handling?

@kenjis
Copy link
Member Author

kenjis commented Jun 15, 2022

This is pretty bad behavior. Does DBDebug control anything else? Or is it just error handling?

Probably major behavior change is throwing a Exception or returning false.
But we need to investigate.

@MGatner
Copy link
Member

MGatner commented Jun 15, 2022

For sure. I favor exceptions more than most of the team, so take it with a grain of salt but it seems to me anytime you "return false" to indicate failure and have a hidden error log that should have been an exception.

@kenjis
Copy link
Member Author

kenjis commented Jun 15, 2022

I think this should be changed to always throw an exception on this matter.

Since it is a BC, I think it needs to be configurable for exception mode and false mode.

@MGatner
Copy link
Member

MGatner commented Jun 15, 2022

What about something like Config\Feature::$databaseExceptions that we recommend turning on in 4.3?

@kenjis
Copy link
Member Author

kenjis commented Jun 15, 2022

Yes, something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Pull requests that changes tests only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants