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

Intermittent error when publishing, after adding tags or categories: "Publishing failed. Error message: Sorry, you are not allowed to assign the provided terms" #36274

Closed
lakellie opened this issue Sep 24, 2019 · 64 comments
Assignees
Labels
[Closed] Fixed Issues explicitly fixed with PRs. Do not use for no longer reproducible issues. Posts [Pri] High Address as soon as possible after BLOCKER issues [Type] Bug

Comments

@lakellie
Copy link

lakellie commented Sep 24, 2019

I ran into this error in 15468043-hc today. Upon researching it, I found no existing reports, but I did find many Zendesk tickets, all dated from mid-July up until now, where the error was mentioned (all with no resolution):

2281003-zen, 2375861-zen, 2186010-zen, 2336103-zen, 2183102-zen, 2352755-zen, 2243803-zen, 2311951-zen, 2333250-zen, 2161172-zen

As far as I know, these are all simple sites.

The error appears across the top of the editor and looks like this: https://cld.wthms.co/bZ9Rrb

For the tickets where the user was specific enough, the common thread is that they had added a category or tag to the post before trying to publish it. In my chat today, the issue was having added a tag. The post could be published fine without that tag added, but once the tag was added, it could not be published.

As a workaround, the tag could be added via quick edit in wp-admin.

It does not appear to be a browser issue, as I could replicate the issue myself in a support session for the user in chat today, and the issue persisted across multiple browsers (Chrome and Firefox) for that user.

I also found this when researching the error message - https://github.com/WordPress/WordPress/blob/master/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Any idea what might be causing this?

@donpark
Copy link
Contributor

donpark commented Sep 24, 2019

Source of the error message is POST REST API handler in Core. When an API is CREATABLE or EDITABLE, check_assign_terms_permission() method of WP_REST_Posts_Controller class is called and it's failing when a user lacks permission to assign, meaning create or update, terms.

@formosattic
Copy link

+1 15689980-hc, issue happened when adding tags.

@donpark
Copy link
Contributor

donpark commented Oct 3, 2019

I was able to reproduce this bug although not consistently.

UPDATE: Now I can't reproduce the bug at all. Elusive.

@Robertght
Copy link

@donpark Found another case here: 2425866-zen

@donpark
Copy link
Contributor

donpark commented Oct 17, 2019

@Robertght Sorry but I no longer work for A8C.

@kcswong
Copy link

kcswong commented Nov 28, 2019

Seems to be another report in 16975579-hc

@JoshuaGoode
Copy link

Encountered this while adding tags to a portfolio project: 17282693-hc & 2557371-zen

@marcuswisecaesar
Copy link

Not intermittent for me happens when publishing a one-word tag like fashion, or music

19989830-hc & 2847839-zd

@scosgro
Copy link

scosgro commented Sep 1, 2020

Another report in 22914939hc

@donalirl
Copy link

Another report in #24119597-hc, though the cause is unclear

@wynwin
Copy link

wynwin commented Sep 15, 2020

Another report here: 24133818-hc - I have asked the user if they notice this happen with specific tags/categories, so I can try and reproduce.

@darnelldibbles-zz
Copy link

Another report here: https://wordpress.com/forums/topic/saving-my-post-3/

@smithkyle45
Copy link

New report of this issue in 24409620-hc

@kristarella
Copy link

Another one in 24502294-hc
I asked them to remove the tags and try to publish, which seemed to work.

@ktyfuller604
Copy link

The issue occurred when scheduling as well - 24031031-hc

@wynwin
Copy link

wynwin commented Oct 5, 2020

Another one 24570082-hc

@lakellie
Copy link
Author

Another report in 3510459-zen

@happychait
Copy link

A customer reported this on Safari on iPad in 156380-hc

@JoshuaGoode
Copy link

A newer report appears to have been opened that seems related: #45758

If it's the same, we can probably close that one in favor of this one and copy over relevant info there.

@cathymcbride
Copy link
Contributor

Moving to prioritized backlog.

@kosiew
Copy link

kosiew commented Jan 11, 2021

#3638164-zen

@formosattic
Copy link

27037033-hc

@tbradsha
Copy link
Contributor

3642645-zen

@Copons Copons added the [Pri] Normal Schedule for the next available opportuinity. label Jan 20, 2021
@kriskorn
Copy link
Contributor

3677729-zen

@fresatomica
Copy link

@philnick206
Copy link

Reported in #13954900-hc

@StefanNieuwenhuis
Copy link
Contributor

Trying to reproduce this issue but not having any luck. 🤔 cc @StefanNieuwenhuis Would you mind giving this a test as well when you get the chance?

@jeyip sure! I'm unable to reproduce it but I did some digging on the check_assign_terms_permission() method to provide some context on the checks/prerequisites.

After retrieving the taxonomies names, we check if the current user has permission to assign them to the post. This happens here, with the current_user_can() method.

The current_user_can() method:

  1. Retrieves the current user and checks its existence.
  2. It then checks if the user has the correct "capability" (in our case assign_term).
  3. The has_cap method calls the map_meta_cap method, which is a huge switch that checks capabilities.
  4. It retrieves the term from the DB, checks if the term is valid, and returns a do_not_allow capability when invalid. My suspicion is that this is what's causing the error.

Next steps

  1. replicate the issue on a simple site (like @jeyip suggested)
  2. check the user's permissions
  3. check how this relates to the above findings.

@davipontesblog
Copy link
Contributor

@davipontesblog @fernmed or anyone else -- would it be possible to get permission from a client to attempt to reproduce the issue on their site?

@fernmed would it be possible to follow up with the user here to ask if we can try to reproduce the error on their site? I think this would involve making an update on a post, or maybe creating a draft would suffice... @jeyip is this correct?

@StefanNieuwenhuis
Copy link
Contributor

@davipontesblog @fernmed or anyone else -- would it be possible to get permission from a client to attempt to reproduce the issue on their site?

@fernmed would it be possible to follow up with the user here to ask if we can try to reproduce the error on their site? I think this would involve making an update on a post, or maybe creating a draft would suffice... @jeyip is this correct?

This is correct! It would be great if we can get some data from the Dev Tools console & network tabs. This helps us to narrow down the issue.

@fernmed
Copy link

fernmed commented Mar 5, 2021

I made the request with the user for further testing.

3794477-zd

@wpshellbelle
Copy link

Another report at 3781308-zen

@simison
Copy link
Member

simison commented Mar 8, 2021

We have a job that tries to save a post as a draft via API and suffers from this frequently. If we just have a diff that adds logging in all the possible places where this might go wrong, we could try to capture what happens.

Discussed p1615189993041800-slack-dotcom and especially p1615196213117200-slack-create-gardeners

@jeyip
Copy link
Contributor

jeyip commented Mar 8, 2021

If we just have a diff that adds logging in all the possible places where this might go wrong, we could try to capture what happens.

Great suggestion! I'm in the process of setting up a diff now, but it will definitely need a few extra set of eyes for code review. It'll be my first time using our logging platform and I also want to make sure we're capturing all possible spots this error might be manifesting.

@mreishus mreishus self-assigned this Mar 9, 2021
@mreishus
Copy link
Contributor

mreishus commented Mar 10, 2021

Steps to Reproduce

  • Start creating a new post on a WPCOM simple site.
  • Type something in the title and body
  • Create a new tag and assign it to the post: MyTag1.
  • Create a new category with the exact same name of the tag you just made and assign it to the post: MyTag1.
  • Press publish and you should see the error message.
  • If you are a WP.com SuperAdmin, this might not work as you are patched to have all capabilities. I removed this check when I was testing, however I currently don't know if that was necessary to recreate the bug.

Video:

assigned-terms-bug-Peek.2021-03-10.15-53.mp4

Technical Details

  • Most of the code involved is core WordPress.org code. However, the bug doesn't happen on a standalone .org site. The bug may belong to .org multisite code, or it may belong to an .com optimization. Currently unsure.
  • In my example above, I added a TestPost10 category and a TestPost10 post_tag. Both of these are stored as terms in the WP database.
    • On a standalone .org site, I will have two separate term_ids for the TestPost10 category and the TestPost10 post_tag.
      • For example, the TestPost10 category might be term_id=12345, and the TestPost10 post_tag might be term_id=12346.
      • That means the term_id alone is specific enough to identify one of those items.
    • On my .com simple site, there will be one term_id shared between the TestPost10 category and the TestPost10 post_tag.
      • For example, the TestPost10 category might be term_id=12345, and the TestPost10 post_tag might also be term_id=12345, the same id.
      • That means the term_id alone is not specific enough to identify one of those items. You will also have to specify the taxonomy, which is either post_tag or category.
    • The _terms table will actually have two different term_ids for the terms. However, the _term_taxonomy table will file the first term against two different taxonomies.
+-----------+------------+------------+------------+
| term_id   | name       | slug       | term_group |
+-----------+------------+------------+------------+
| 123456756 | TestPost10 | testpost10 | 0          |
| 123456757 | TestPost10 | testpost10 | 0          |
+-----------+------------+------------+------------+
There are two TestPost10 terms, the "..56" and "..57" ids.

+------------------+-----------+----------+-------------+--------+-------+
| term_taxonomy_id | term_id   | taxonomy | description | parent | count |
+------------------+-----------+----------+-------------+--------+-------+
| 17               | 123456756 | category |             | 0      | 1     |
| 16               | 123456756 | post_tag |             | 0      | 1     |
+------------------+-----------+----------+-------------+--------+-------+
The "..56" id is set up as both a category and a post_tag, and the "..57" id is unused.
  • Some functions that retrieve a term_id will have an optional taxonomy parameter that can be passed. If it's not passed, the functions will look up all matches to the term_id, and if only one is found, all is good. If two are found, it doesn't know which one should be returned, and throws an error.
    • One of the permission checks if asking if the user is able to assign the term, but it ends up fetching the term by term_id only without specifying a taxonomy, so it is ambiguous if it is looking up the tag or the category.
    • This doesn't seem to be the full story, because after creating the error, you can simply wait a minute or two and try again, then it will work. Why should it start working? Currently unknown.

Stack Trace

  • The posts controller calls has_cap( 'assign_term', $term_id ) to see if the user can assign the term: Link
  • has_cap(...) calls map_meta_cap(...): Link
  • map_meta_cap(...), when looking up the assign_term permission, calls get_term( $term_id ) to get the term without knowing which taxonomy it belongs to yet: Link
  • get_term( $term ), when provided an integer $term and no optional taxonomy argument, proceeds to call WP_Term::get_instance( $term, $taxonomy ). In this case, $term is still an integer and $taxonomy is the empty string. Link
  • get_instance( $term_id, '' ) looks up all rows matching that term_id. In the dotcom simple site, it could be multiples. Link
  • get_instance( $term_id, '' ) would filter multiple results, if a taxonomy was provided as the second argument. In this case it isn't, so this filter code won't be used: Link
  • get_instance( $term_id, ''), If not provided a taxonomy filter, looks for multiple results. If multiple results are returned, and there are multiple valid taxonomies, it returns an error: Link

Proposed Fixes

None at this time; I'm currently unsure the best way to fix this, but at least I do have a good handle on what's going on. I would first like to determine if the bug is happening on .org multisite with no .com specific code before deciding on an approach.

Followup Resources

  • p7H4VZ-2Vd-p2 P2 summarizing my findings as of 2021-03-12
  • 521-gh-Automattic/dotcom-manage dotcom issue where specific dotcom code is pointed out

@jeyip
Copy link
Contributor

jeyip commented Mar 10, 2021

Create a new category with the exact same name of the tag you just made and assign it to the post: MyTag1.

Oof this definitely seems like a problem. @mreishus While I think that what you've found is probably contributing to the problem we're seeing, there are a number of instances where users see the "Publishing failed." error where the post title and post tag / category added do not match.

Here are a few examples I found:

  • 17282693-hc
    • Title: “TransAtlantic” at Boston Sculptors Gallery
    • Tag: Boston Sculptors Gallery
  • 24133818-hc
    • User supposedly tried on a variety of different posts
    • Tag: SEO

Maybe, to build on your findings, the term doesn't have to exactly match. Maybe the term just has to be included in the title (e.g. The Boston Sculptors Gallery tag is part of the "Transatlantic" at Boston Sculptors Gallery title) ? I'll test a few things out in my own environment and leave updates here.

Update:
Ah ignore what I wrote above 🤦‍♂️ . I misread your comment. Awesome sleuthing mreishus! This makes a lot of sense. To build on your findings, cases like 17282693-hc and p3hLNG-18a-p2 that dealt with "Publishing failed." error appear to have duplicate terms (Boston Sculptors Gallery and mu-plugins respectively).

@donalirl
Copy link

Encountered in #27098180-hc. They initially got the error but were able to publish it the second time. There are no categories or tags assigned to the post right now.

@benchilcote
Copy link

Another report 3791219-zen.

@mreishus
Copy link
Contributor

mreishus commented Mar 11, 2021

I have not found a way to recreate the bug on dotorg multisite, both before and after forcing global_terms_enabled() to be on. This may be a dotcom specific bug. Up next is investigating just why the tag and the category are getting the same term_id, when they don't on dotorg.
2021-03-11_10-23
^ This is an incomplete analysis as the bug is happening in the _term_taxonomy table, not the _term table. I have updated this comment with details. I also rechecked the dotorg site I made and the taxonomy entries are using different term_ids, so the bug remains specific to dotcom.
2021-03-11_14-53

Edit: I have tracked it down a .com specific plugin.

Followup Resources

  • p7H4VZ-2Vd-p2 P2 summarizing my findings as of 2021-03-12
  • 521-gh-Automattic/dotcom-manage dotcom issue where specific dotcom code is pointed out

@tbradsha
Copy link
Contributor

Got it in 28348375-hc. Trying twice didn't work, so I had them publish without tags or categories (success!) and then add the tags and categories after.

@worldomonation
Copy link
Contributor

Issue reproduced during my Back to Basics user testing run.

Steps I took:

  1. open a post.
  2. add new post tags.
  3. click on Launch.
  4. cancel the new launch flow (one that looks similar to Gutenboarding).
  5. see error.

Post link: https://e2eflowtesting2021031201gardening4.wordpress.com/2021/03/12/retro-cameras-galore/

@kwight
Copy link
Contributor

kwight commented Mar 16, 2021

D58727-code under review.

@david-binda
Copy link
Contributor

D58727-code has been shipped. Hopefully this addresses the issue 🤞

@kwight kwight closed this as completed Mar 17, 2021
@cathymcbride cathymcbride added the [Closed] Fixed Issues explicitly fixed with PRs. Do not use for no longer reproducible issues. label Mar 18, 2021
@druesome
Copy link
Contributor

@david-binda I just got another report of this happening in 28628867-hc. User says they entered a bunch of tags and wasn't able to save their draft. They said they added 17 or so tags. Reducing the number allowed them to save. Site is https://photoferret1.com/

@druesome druesome reopened this Mar 25, 2021
@david-binda
Copy link
Contributor

@druesome my understanding of this issue is that it was WPCOM specific, due to it's multisite nature and global tags turned on (+some custom logic in a mu-plugin). https://photoferret1.com/ is hosted on Atomic, so the issue is likely different.

@kwight
Copy link
Contributor

kwight commented Mar 25, 2021

@druesome do you know if they got the error given by the OP? If not, a new issue would be best.

@kwight
Copy link
Contributor

kwight commented Mar 29, 2021

I'm going to close this again – @druesome if there's still an issue, feel free to reopen if the user got the same error, otherwise a new issue would be better. 👍

@kwight kwight closed this as completed Mar 29, 2021
@katiebethbrown
Copy link

katiebethbrown commented Mar 30, 2021

@kwight - I've got an atomic site in chat seeing the same error when adding a tag to posts in 27939677-hc. Happens with just a single tag, and I can replicate in a support session as well.

terms

Screen Shot 2021-03-30 at 2 22 59 PM

@kwight
Copy link
Contributor

kwight commented Apr 1, 2021

It looks like the additional reports are specific to Atomic; I'm closing this issue, and we can follow up further in #51640.

@kwight kwight closed this as completed Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Closed] Fixed Issues explicitly fixed with PRs. Do not use for no longer reproducible issues. Posts [Pri] High Address as soon as possible after BLOCKER issues [Type] Bug
Projects
None yet
Development

No branches or pull requests