question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected behaviour with getSubfieldsValues in update trait

See original GitHub issue

There appears to be an issue with function getSubfieldsValues in the update trait. Specifically the part that handles fields that have a dot in the name

https://github.com/Laravel-Backpack/CRUD/blob/bdf1349c88f8f621f568c97f6cad16e26f788b62/src/app/Library/CrudPanel/Traits/Update.php#L255-L266

Let assume we have a model called Address with attribute street_number having an integer value of 1 so $name = "address.street_number"

Right after this block of code is executed https://github.com/Laravel-Backpack/CRUD/blob/bdf1349c88f8f621f568c97f6cad16e26f788b62/src/app/Library/CrudPanel/Traits/Update.php#L260-L263 The iterator has the following value $iterator = 1

Is there a reason why the code assumes the attribute value would be a string if it is not a model instance ? https://github.com/Laravel-Backpack/CRUD/blob/bdf1349c88f8f621f568c97f6cad16e26f788b62/src/app/Library/CrudPanel/Traits/Update.php#L258-L259

Given that iterator now contains a number, as you can expect

!is_string($iterator = 1) // true
&&
!is_null($iterator = 1) // true

$this->getModelWithFakes($iterator = 1)->getAttributes()

So when getModelWithFakes is called it results in an exception when class_uses_recursive is called using a value that is not a model https://github.com/Laravel-Backpack/CRUD/blob/bdf1349c88f8f621f568c97f6cad16e26f788b62/src/app/Library/CrudPanel/Traits/Update.php#L195-L202

Solution: If the idea is to call getModelWithFakes only in the case when $iterator is a model then perhaps the code could be rewritten as

$iterator instanceof \Illuminate\Database\Eloquent\Model ? $this->getModelWithFakes($iterator)->getAttributes() : $iterator

@pxpm

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pxpmcommented, May 20, 2022

Hello @fournodes

Thanks for the report. Unfortunately I was not able to reproduce it, maybe I am using the wrong usecase.

From my understanding some of your subfields are dot.notation fields. We have the same example in our demo: https://demo.backpackforlaravel.com

In Monsters & Stuff menu, you will find the Story for example, this Story HasMany Monsters, and those Monsters have some fields inside that use dot.notation as for example address.street.

Can you please provide me a more detailed implementation of your usecase so I can attempt to reproduce it ?

Cheers

0reactions
tabacitucommented, May 22, 2022

Merged. Thanks guys! Will be available starting Monday when we release a new patch version.

In regards to the is_a() vs instanceof debated… I’ve merged it with is_a(). Not because I think it’s more readable (I think they’re both readable) but because… the performance improvement is so small that it can be approximated to zero. Let’s keep the context in mind - we’re running on a “fat” framework here, Laravel itself uses is_a throughout its code, which gets run upon every request. In my opinion, one more call will not do any harm, on less call will not do any good. Let’s not let this distract us from squashing bugs, it really doesn’t matter 💪

Thanks again, cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected Trait Behavior - scala - Stack Overflow
It seems that singleton types without members are type-equivalent somehow here. Perhaps it's a bug (you filed a ticket).
Read more >
Genotypic differences in behavioural entropy - NCBI - NIH
Intra-genotypic variability (IGV) occurs when individuals with the same genotype, raised in the same environment and then tested under the same conditions, ...
Read more >
Traits: Defining Shared Behavior - The Rust Programming ...
A trait defines functionality a particular type has and can share with other types. We can use traits to define shared behavior in...
Read more >
What the Big Five Personality Traits Can Tell You - Healthline
Your personality is unique to you and an important part of who you are. It includes your preferences, mannerisms, and behavior. Together, these...
Read more >
Personality Can Change Over A Lifetime, And Usually For The ...
Sudden, dramatic changes in personality are rare. Due to their effects on behavior and continuity over time, personality traits help shape ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found