-
Notifications
You must be signed in to change notification settings - Fork 824
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
BUG Manually create singleton when building table #9952
BUG Manually create singleton when building table #9952
Conversation
This may be a naive fix, but at first glance looks like it's working fine. Not quite sure if this is something that is testable. |
I'll give it a crack. I think it is testable. |
Just clarifying: I meant "testable" as is "can write unit test to cover this use case". I tested it locally with a similar example as the one provided by @dhensby. |
Yep, I got what you meant. That's why I wrote two independent sentences :) I think it's testable as long as we can assert what db tables get built and what columns they contain. |
a slight variation on #9951 (which I'll close). I had targeted 4.2 as it is potentially the lowest supported version of the framework, given it's a fairly high impact bug it deserves to be back-ported as far as reasonable. |
I don't think we can add unit tests for this... When the database is built for tests it doesn't use this code at all - it uses So any test cases written to test this functionality right now would fail with this PR because the method used for creating test database tables is using
|
cdff042
to
6a33725
Compare
6a33725
to
1140cb3
Compare
I've found what I think is a pretty clean solution to be able to test this - I've created a new class to hold the logic that is shared between |
Scrutinizer failure is unrelated to this PR |
src/ORM/Connect/TableBuilder.php
Outdated
// If we have additional dataobjects which need schema (i.e. for tests), do so here: | ||
if ($extraDataObjects) { | ||
foreach ($extraDataObjects as $dataClass) { | ||
$SNG = new $dataClass([], DataObject::CREATE_SINGLETON); | ||
if ($SNG instanceof DataObject) { | ||
$SNG->requireTable(); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This runs for each input dataClass whereas previously it was outside of the loop. Should this be moved one level up after the first foreach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, yes - my bad. I'll fix that.
Nice work @GuySartorelli! |
7017431
to
0482444
Compare
Probably also worth me mentioning that I have confirmed the tests I've added fail before the changes in this PR. |
Cool, thanks for hopping in and pushing it over the line. |
I targetted |
I would probably lean towards a patch fix due to the nature of the issue, but it can really be argued for both ways. But since we made several workarounds, if I didn't know about this change and just simply applied a new patch release, the site would stop working since the data would become inconsistent in different tables. But also I'd prefer fixing that and having working MTI — 🤷 |
I'll defer the branch targetting conundrum to whoever wants to merge this - happy to retarget and fix commits to match whatever branch the merger chooses. |
@maxime-rainville wanna decide this one for us? :-D I'm happy to merge it as a fix with your blessing. |
Test in local environment. All works. |
Thanks for jumping in for the merge, @sabina-talipova, though I sort of wanted to know what Max's opinion was. Since we've now merged this into |
It is adding a brand new Class to our API, so it should ship in a minor release. If this was a major bug and people had been screaming for a fix forever, I'd say maybe it's worth shipping this in a patch release, but as far as I can tell it's always been broken and it took us until last year to notice. It's a smallish change but it affects some pretty low level methods. I would rather take it through our regular minor release regression test. |
Because we use
singleton
to get class references when building table, if you try to inject over a class, it's table will never be created.Parent issue