Skip to content

Conversation

@macaws
Copy link

@macaws macaws commented Aug 4, 2025

This PR attempts to address a problem when an entire column is null.

Problem

The current AsFluent implementation returns null when the database column is null, causing runtime errors when developers try to use Fluent methods:

// This crashes if preferences is null in database
$user->preferences->get('theme'); // Call to a member function get() on null

Rationale

By always returning a fluent, we can prevent errors when calling ->get() blindly. Since you can't set a default value for json columns in MySQL, it becomes particularly tricky to add this AsFluent cast to existing datasets.

This may be a "breaking" change if anyone is dependent on checking for null to determine if the column was set - but realistically, most developers want to work with an empty Fluent object rather than handle null checks.

@macaws
Copy link
Author

macaws commented Aug 4, 2025

Seems to be an issue with the test itself re: failing tests:

 docker.io/library/mysql:5.7
  /usr/bin/docker create --name 48c8cef7de12443b9d8df561ee116ba8_mysql57_72b477 --label a6ae00 --network github_network_122031dbbcd341cda0fcf19f9eaff7af --network-alias mysql -p 33306:3306 --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -e "MYSQL_ALLOW_EMPTY_PASSWORD=yes" -e "MYSQL_DATABASE=forge" -e GITHUB_ACTIONS=true -e CI=true mysql:5.7
  51c0342d17ef850461b7982a72e48ede88a50abb6cb7202e150ffee1e650bd3d
  /usr/bin/docker start 51c0342d17ef850461b7982a72e48ede88a50abb6cb7202e150ffee1e650bd3d
  Error response from daemon: failed to set up container networking: driver failed programming external connectivity on endpoint 48c8cef7de12443b9d8df561ee116ba8_mysql57_72b477 (b18c4b55d5dc2693c09f5f0afbe71fc73fdd21cbc76fdca07925af5d527d0695): failed to bind host port for 0.0.0.0:33306:172.18.0.3:3306/tcp: address already in use
  Error: failed to start containers: 51c0342d17ef850461b7982a72e48ede88a50abb6cb7202e150ffee1e650bd3d

@taylorotwell
Copy link
Member

This would technically be a breaking change as implemented. Note I think you could just do $user->preferences?->get('theme')

@macaws macaws deleted the fix/always-cast-fluent-even-when-null branch August 4, 2025 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants