Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The current implementation of views handler for dblog present several problems:
wid
anduid
fields of the watchdog table are using numeric fields handlers: When a site has more than 1000 logs, the Logs id could use a separator to format the logs, for example 1,200. If this field is used in a link to link a log event this breaks the link. See: #2849797: dblog link broken with > 1000 watchdog entries- The use of the in_operator filter handler for type filter makes impossible deprecate
_dblog_get_message_types
the (See #2458191: Provide a storage backend for dblog module) - The relationship between
watchdog
table and theuser
table is incorrect. This makes impossible to get for example the username of the author name that triggered an error.
.
The mentioned problems blocks the progress on several patches:
- #2458191: Provide a storage backend for dblog module
- #2015149: Replace dblog recent log entries with a view
Proposed resolution
- Update the numeric fields form the watchdog table (wid, and uid) to use the standard plugins.
- Update the relationship of uid to join the
users_field_data
for more flexibility in watchdog based views. - Update the watchdog.types filter from
in_operator
with a callback to a custom filter.
Also the dblog module don't have a good test coverage for views integration (for example filters are not tested). It would be nice to include some integral test coverage for views.
The upgrade path required for this patch includes two steps.
- Use a hook_update_N to update all the views that use the watchdog as base table.
- Provide a hook_entity_type_presave hook to update contrib modules that provide their own watchdog based views. (See #2870724: Define and document best practices for configuration entity updates/bc layers)
Remaining tasks
- Write the upgrade path. done
- Write tests for the upgrade path. done
- Extend functional tests for views done
User interface changes
wid
and uid
fields will not provide anymore settings related to numeric formatting.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#102 | interdiff-2851293-93-102.txt | 2.17 KB | dagmar |
#102 | 2851293-102.patch | 38.66 KB | dagmar |
Comments
Comment #2
dagmarAn initial patch.
Comment #3
dagmarComment #5
dagmarIt seems we cannot test the view with the previous values defined in the hook_views_data. Some advice from the views maintainers here?
Comment #6
Lendude@dagmar since the relationship isn't changed in the post_update hook there is no need to test the change in the post_update test. A normal (non-update) test that checks that relationship might be nice.
bit of quick nitpicking:
I don't think we do @file anymore?
The relationship isn't changed in the post update hook.
missing period at the end
do we want to remove this?
Comment #7
jibranComment #8
dawehnerTo be honest I'm personally not convinced by testing things before running update.php. Accessing stuff can cause side effects, like maybe some caching of schema in this issue.
Comment #9
xjmI think the removal of the VDC tag was an xpost. Tagging for subsystem maintainer review also to make sure @dawehner's comments in #8 are taken into consideration before this might be committed.
Comment #10
LendudeUhh if running update.php doesn't clear those caches, isn't that something we would want to detect? Cause that sounds like trouble to me :)
Comment #11
dagmarThanks everyone. I added the code to cover the change in filters.
Included in this patch.
I removed that code, we can add it again after more discussion.
Comment #13
dagmarComment #14
dagmarComment #15
dagmarWe need to include the conversion of the types into a new custom handler. See #2458191-66: Provide a storage backend for dblog module
Comment #16
dagmarNo interdiff sorry I renamed a lot of files.
This patch do 3 things:
This patch makes really simple changes, the complexity is on the tests (and maybe in the upgrade path).
Comment #18
dagmarComment #20
dagmarI tested this manually, this should work.
Comment #21
dagmarI forgot the interdiff.
Comment #22
dagmarAnd this should remove the other error from #18.
Comment #25
dagmarRe-rolled after the
array() -> []
conversion.The interdiff shows the relevant change.
Comment #26
dagmarWoops, I forgot a part of a file.
Comment #29
dagmarComment #30
dagmarComment #31
dagmarAny chance to get a review on this? This is blocking
#2015149: Replace dblog recent log entries with a view
#2458191: Provide a storage backend for dblog module
The last one also blocks.
#2852990: Deprecate dblog_filters
#1325736: Create a consistent method to link to watchdog log reports
Comment #32
dagmarRe-rolled after #2860096: Remove api doc groups for updates eg. updates-8.2.x-to-8.3.x
Comment #33
LendudeManually tested this and the changes are good and the update works nicely.
Unrelated change
This seems very strange to me. This is great for the exposed filter, but for a non-exposed filter this makes no sense. This means when I'm building the View, the type of message I want to filter on, needs to be present in the database at that time. But it seems that was how this previously worked too, so this is not the place to change this behaviour probably.
Class name can be a bit more descriptive and needs to end in Test (I think)
Start with a capital letter or quote type.
Why random? why not use fixed test parameters?
not needed
not needed
Comment #34
dagmarThanks for the review @Lendude!
1. Agree, but in my opinion is ok to fix this here. We are modifying a lots of entries of the same file and that will leave the hook in good shape.
2. Logs types are dynamic, it seems this is the only way to proceed.
3. I renamed it to
DblogFiltersAndFieldsUpgradeTest
.4. Fixed.
5. The code of that method was originally present in the test, I abstracted that part of the code into a new method. There are a lot of work to improve the log generation for tests (See #2848914: Move DbLogTest::generateLogEntries() into a Trait]) For now I just renamed the method to
createLogEntries
.6/7. Fixed.
Comment #35
Lendude1. Yeah I think it's fine sneaking it in here.
2. For the non-exposed filter a string filter would make more sense to me, but since we can't vary by exposed/non-exposed and this was how it was working before, so yeah lets stick with this.
5. Yeah that follow up sounds like the way to go, so this looks good for now.
6/7:
You got one that I missed, and missed two that I pointed to :)
So just 6/7 and then this looks ready to me.
Comment #36
dagmar@Lendude Thanks!
Comment #37
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComments should (noramlly) begin with a capital letter and end with a full stop / period .
Fixed and attached new patch.
Comment #38
LendudeThis looks ready to me. Nice work!
Comment #39
tstoecklerCoder is not happy with this one:
Also:
This should be shortened so it fits in one line.
Comment #40
dagmarThanks @tstoeckler.
Comment #41
tstoecklerThank you, perfect!
Comment #42
jibranSome coding improvements. Should we wait for @dawehner here so that we can remove the subsystem review tag?
Why not $save |= TRUE?
We don't need if here. Just
unset($new_value[$key]);
is fine.This can all be done in one line. unset($arr[key1], $arr[key2], ...);
Let's inject the query service and execute the query here.
Comment #43
dagmarThanks @jibran.
In #11 I addressed the concerns from @dawehner. So I think is ok to remove the
Needs subsystem maintainer review
tag.Actually, this will be replaced by the new dblog StorageBackend when #2458191: Provide a storage backend for dblog module be ready. So, this is not the right approach. We are trying to avoid sql queries from outside the StorageBackend.
Comment #44
alexpottWell @Lendude is also a subsystem maintainer but yeah only a subsystem maintainer should remove that tag. Given that @Lendude rtbc-d the patch I assume he is happy with it but I'd still rather wait for confirmation.
Comment #45
alexpottStrictly there should be a comma after the
]
New line in between the first line and the @return.
Need comma at the end.
Comment #46
alexpottDiscussed with @catch - we think we need to fix this using hook_ENTITY_TYPE_presave() so that default views supplied by contrib and custom modules can be updated too. This means the hook_update_N() needs to determine which views need to be saved again and save them.
Comment #47
dagmarThanks @alexpott for the review and the new patch. The proposed approach discussed by you and @catch seems reasonable. Here is the new patch that use the
hook_ENTITY_TYPE_presave
.Comment #49
dagmarComment #50
jibranI disagree with this direction
hook_ENTITY_TYPE_presave
will be called whenever a view is saved which is not ideal imo. The view integration is introduced in #1874534: Introduce a dblog / watchdog views integration. I doubt that contrib is using this but that's beside the point. We never cared about the default views but we do update the existing views which this patch was already fixing. Updating the config object in preSave means we are creating a mismatch between the default and saved config which is not right.Consider the other side of the picture for a moment not fixing the default views would show the error after importing and views should have to be updated and saved and that's what we actually want so that config can be updated properly.
If we still want to go down preSave road then every time we change the existing views data we have to write the preSave for the respective module which is not ideal. If BC break is the issue then we should consider keeping the original mapping as is and we should consider the new mapping so that contrib can catch up then we can even nuke the update hook altogether. Thoughts?
These changes qualify this patch as a bug.
Comment #51
jibranWe have a relationship defined with users table. Logically speaking it is possible to create a reverse relationship and use the watchdog data in any view so I don't think checking
watchdog
as a base table is the right thing to do here. Do we care about this or not?Comment #52
jibranLet's update the title as well.
If we are doing former then we don't need latter. Every time
users_field_data
table would be available in views the former would show the watchdog fields as well. If we remove latter then it is a BC break even it is not changing the views field plugin id but we are changing the field existing relationship and we need to update those fields as well in post-update hook.Comment #53
alexpott@jibran we've used preSave() before to fix default views - and we do care about default views - #2248983: Define the revision metadata base fields in the entity annotation in order for the storage to create them only in the revision table
Comment #54
jibranIt's sad that no one from VDC has reviewed that patch or +1ed the approach :(
Comment #55
Lendude@jibran, @dawehner and I went into that approach here #2784233: Allow multiple vocabularies in the taxonomy filter and I 'ranted' about it some more here #2810097: Allow views to provide the canonical entity URL of all entities, not just nodes..
Summary: I'm not happy with the approach, but I couldn't find anything better (tried some things in #2784233: Allow multiple vocabularies in the taxonomy filter). We need an post_module_install event that fires after every module install or something.
Comment #56
dagmarIn my opinion, we should not encourage users to join watchdog table from other tables. I cannot image a user case for that. I know this is not 100% related but there is a mention regarding the eventual use of foreign keys to watchdog here: https://www.drupal.org/node/2494221#comment-9957997
Anyway if we need to do that in the future, we can add it without break the BC. The thing right now is that using
{user}
is incorrect because all the actual data of the user actually lives in{users_field_data}
.Comment #58
dagmarComment #59
catchIdeally we'd check if these need deleting before unsetting them, then @trigger_error('...', E_USER_DEPRECATED); when they're found. That way at least once we have phpunit integration with deprecations we'll be able to inform contrib modules easier.
https://www.drupal.org/core/deprecation
Comment #60
dagmar@catch sorry, I don't understand your point. I'm removing those values not because they are deprecated but because they are not part of the
standard
plugin options. Those values are still valid fornumeric
fields and indicate they are deprecated may be confusing, don't you think?Comment #61
catchOh I missed that code is just moving around rather than related to the upgrade path.
The deprecation notice could happen here.
On the question of using hook_ENTITY_TYPE_presave() for this:
It's not a case of caring about default views as such, it's about default configuration in general, and having a standard way to handle this for backwards compatibility.
Using hook_ENTITY_TYPE_presave() looks heavy-handed, but I don't think it's that bad really:
- generally it's a couple of quick if checks
- it allows us to catch any case where a configuration entity might be saved via the API - i.e. created in hook_install() or manually using $entity->save() in test coverage and similar.
- we can remove all this code in 9.0.x
However it'd be good to make it clearer which bit is the bc-layer and which bit isn't, so people don't make the same mistake I just did.
edited to add:
While this has been discussed a few times (especially on the two issues that Lendude linked), the docs on https://www.drupal.org/docs/8/api/update-api/updating-configuration-in-d... don't mention this at all, so we should probably open a new task to update that documentation with the presave approach. While it's not perfect given it's only used for cases that need bc layers I do think it's OK if we document it better (or at least we should open a new generic issue for config entity updates/bc to try to replace the pattern with something better).
Comment #63
xjmSo looks like we have input here from the dblog subsystem maintainer (thanks @dagmar!), a Views maintainer (thanks @Lendude), and a Configuration system maintainer (@alexpott). I think the concern here is around the correct approach for the upgrade path? In #55 @Lendude says it seems nonideal but also that they didn't come up with anything better.
Comment #64
catchI've opened #2870724: Define and document best practices for configuration entity updates/bc layers to discuss the upgrade path approach more generally.
Comment #65
Lendude@catch++
thanks for the great summary and opening the issue.
@xjm++
And yes, hook_ENTITY_TYPE_presave() certainly beats doing nothing.
Took the 'Needs subsystem maintainer' tag off, @dawehners concern was with doing assertions before running updates in the update path test, and we are not doing that currently, so I assume that's ok.
Comment #66
dagmarThanks everyone. This should fix the remaining test. Thanks @Berdir for the hints
Comment #67
dawehnerOOOH, interesting, I had no idea.
You can actually use
\Drupal::moduleHandler
here ...Really good to know!
Comment #68
dagmarThanks @dawehner
Comment #69
dagmarI think all the concerns (#67 and #59) has been addressed. Who want to move this back to RBTC?
Comment #70
alexpottThis could be less complex... just
No loops, no ifs... unset doesn't fail if the thing doesn't exist and can do multiple at once.
Should set strict to TRUE... its a third argument.
Comment #71
dagmarThanks @alexpott
Comment #72
dagmar(17:38:58) alexpott: dagmar_drupal: as xjm suggests dawehner is an excellent final reviewer - he often often offers review swaps for a patch review on anyone else's issue. (One of the many reason's why dawehner is awesome)
@dawehner this is all yours :)
Comment #73
dawehnerDo you mind adding some line of documention that this should be removed in Drupal 9 again?
you could just use an
options callback
instead of introducing a PHP class, see\Drupal\views\Plugin\views\filter\InOperator::getValueOptions
Comment #74
jibranMay I ask why we moved from post-update hook to update hook?
Comment #75
dagmarThanks @dawehner!
We can, but I'm deliberate doing this because we are trying to deprecate
_dblog_get_message_types
and theoptions callback
doesn't support the use of services.@jibran sure! So, hook_update_N is used to fix drupal from a broken state, and post update hooks are used to create content after drupal was fixed . In this case seems appropriated to use hook_update_N for this tasks.
Comment #76
jibranAFAICS there are changes in views plugins and there is no schema change so Drupal is not broken only certain views are broken. Moreover, use of entity API is not a good idea in update hook that's why we introduced the post-update hooks so IMO we should use a post-update hook.
Comment #77
dagmar@jbrian I understand your point, however in my opinion we should use this hook_update_N here just because we can.
If in the future we break the functionality, the tests in this patch will let us know. And then we can decide if this definitely needs to live in a post update hook or there's another way to fix the problem.
This is the first time we use this approach, and i think there is room to experiment with this approach.
Comment #78
dawehnerWhat about making this possible? If you use
controller_resolver
to make this possible.I agree, we should really not use the config entity API, it can causes arbitrary issues you can't see upfront.
Comment #79
dagmarWe still don't have the code to replace this. This is part of #2458191: Provide a storage backend for dblog module. Honestly think we should leave this as is.
So, we have a problem here. Core maintainers are suggesting we should use
hook_update_N
(see #46), but there are other arguments (supported by subsystem maintainer and top core contributor :) ) that indicate this is not a good approach.What do we want to do here? @alexpott, @xjm?
Comment #80
dagmarI'm providing the two approaches here and let core maintainers decide which is the best option. As I said in in #77 the fact that using hook_update_N makes this work and the fact that we have test coverage that ensure this will not break in the future, is enough to go with the hook_update_N approach.
But, what @jibran said regarding the hook schema makes sense too. So both patches with the same functionality and different implementations.
I would like to propose move this to RBTC if there are no other objections and let core maintainers decide which alternative is best.
Comment #82
dagmarComment #83
dawehner@dagmar and @dawehner discussed about this specific issue:
We agreed on trying out the following idea:
* use
hook_update_N
* use config api
* call to
dblog_view_presave()
directlyThis ensure we don't use the entity api, while still working early.
Comment #84
dagmarComment #85
dagmarI spoke with @dawehner and it seems simpler to have a bit of code duplication instead of doing some weird conversion that could eventually stop working in the future.
Comment #86
dagmarComment #87
dawehnerI agree that code duplication here is not a bad thing. Its a once thing, which probably will not be adapted. If we want to adapt it we probably should rebuild it.
Comment #88
dagmarBased in my experience during the live commit in Baltimore, I have a better understanding of the necessity of a detailed issue summary. I hope my changes now make easier to review this patch.
Comment #89
dagmarComment #90
jibranThis is actually not a bug and not needed at all. Given that we already have a relationship to user_field_data this adds confusion.
The relationship shows the user details of the log entry. Whereas this doesn't make sense why in a user view we want to show its log entries by default.
Comment #91
dagmar@jibran this is actually a bug. If you try to display the username of the user that triggered a log, you can't.
Comment #92
jibranThat's not true.
Please see following:
Comment #93
dagmarWe have a quick IRC conversation with @jibran and now I understand what he was saying. So the thing is, with this change:
This the following code is not neccesary:
My comment in #91 was because I thought this was the default behavior without applying the patch. Thanks @jibran!
Comment #94
jibranThank you! @dagmar for fixing that.
We already have a name field in the view and we have these asserts so we already have a test coverage for the bug described in #91. Back to RTBC.
Comment #95
dagmarComment #97
dagmarUnrelated fail. Back to RBTC.
Comment #98
alexpottShould link to the change record.
These should point to the change record.
It's great having these deprecation notices here because it means we'll know to remove it for 9.x
Comment #99
akashkrishnan01 CreditAttribution: akashkrishnan01 at Google Summer of Code commentedpatch has been re-rolled, points have been changed as alexpott mentioned
Comment #100
akashkrishnan01 CreditAttribution: akashkrishnan01 at Google Summer of Code commentedComment #102
dagmar@akashkrishnan it seems you forgot to add half part of the patch. Please read the patch documentation it seems you missed step 9. And also remember to provide an interdiff
Change record added: https://www.drupal.org/node/2876378
Comment #103
jibranThanks, @dagmar. I have updated some wording and title for the change notice.
Comment #104
alexpottCommitted ef0fe5d and pushed to 8.4.x. Thanks!
I've credited @jibran, @Lendude, @dawehner and @catch for reviewing the patch. @xjm and @tstoeckler thank you for your comments.
@akashkrishnan thanks for trying to address #98 in #99. I've not credited you because you didn't provide an interdiff and your patch was half formed. It's good practice to review your patches before uploading. A good indication that something has gone wrong when you are only making minor changes is patch size. @dagmar has provided you useful links. Thanks for contributing!