-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Don't build latest on webhook if it is deactivated #4733
Conversation
readthedocs/core/views/hooks.py
Outdated
@@ -42,16 +42,26 @@ def _build_version(project, slug, already_built=()): | |||
# these will build at "latest", and thus won't be | |||
# active |
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.
Not really sure if this short circuit
is saving resources, it only saves one query (probably). I think this piece only adds complexity to the code. Let me know if you want me to remove this.
This is weird... for some reason the test failed only on python2, I tested it locally with python3, the test fail there too. |
If someone is reviewing this, please test locally 9bec7e0 with python3 |
readthedocs/core/views/hooks.py
Outdated
.filter(slug=slug) | ||
.exists() | ||
) | ||
if version_exists: |
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.
Is there a reason we want to do this check only when the latest version is active? I'm not 100% sure, but it seems like we'd want it to run regardless of the state of the latest
version.
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.
A user deactivates latest, here we try to build latest when the branch is master
, as a side effect the version gets activated.
I just realized that we may need this strange logic, as this allows us to update the version list... Maybe we want to merge this after #4450 ?
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.
I'm not sure to follow @stsewd. If the branch is master
we will have two versions: master and latest.
When a webhook for master
is received, we will want to build both if they are enabled. If latest
is disabled we will want to build master
version. Right?
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.
Yup, master
is still building here, the code above bellow handle that case, that's why I'm suggesting to remove this block too, as I think it only adds complexity to the code. But without building latest
(activated or not) we don't have a way of updating the branch list, users will need to trigger a build to any other version to get the latest tags/branches on rtd.
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.
But without building
latest
(activated or not) we don't have a way of updating the branch list, users will need to trigger a build to any other version to get the latest tags/branches on rtd.
A similar case is already happening in RTD:
- import your project
- create a new branch in your repository
- go to Versions tab in RTD
Your new branch is not there.
I think we should implement a completely separate way of syncing our version with the ones on the repo. I mean, we should not build anything if we receive a webhook, but update the versions list first. Then, decide what we need to build and trigger build those versions.
(this is probably out of the scope of this PR, but maybe worth thinking a little about this here)
that's why I'm suggesting to remove this block too, as I think it only adds complexity to the code
This is the part where I don't follow you :(
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.
#4450 this issue is trying to solve the sync problem, so, maybe is worth to solve that first? What do you think?
This is the part where I don't follow you :(
This line just check if we are receiving a main branch
That way we build latest and the main branch at the same time. For the rest of versions, this is the normal flow
So, at the end we are just saving one loop, even we aren't saving queries to the db now
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.
#4450 this issue is trying to solve the sync problem, so, maybe is worth to solve that first? What do you think?
I'm fine of merging this PR first if it doesn't introduce another issue/bug/wrong workflow/confuse users.
#4450 is already a problem, and this PR doesn't fix it. Which is fine to me. I don't want to fix that issue in this PR, but I want this statement to be correct to merge:
When a webhook for master is received, we will want to build both if they are enabled. If latest is disabled we will want to build master version.
Anyway, I'm still confused with this chunk of code and it seems that talking async doesn't clarify things. We should chat/talk in sync mode.
Seemed to work here on your latest branch. |
@ericholscher with only the test? |
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.
Changes make sense to me, but I'd like to continue the discussion before merge:
- we should log that we are not building
latest
when it's disabled. - I think we should build the
master
branch even iflatest
is disabled.
If we arrive at the same conclusion there, I'm happy to merge.
readthedocs/core/views/hooks.py
Outdated
.filter(slug=slug) | ||
.exists() | ||
) | ||
if version_exists: |
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.
I'm not sure to follow @stsewd. If the branch is master
we will have two versions: master and latest.
When a webhook for master
is received, we will want to build both if they are enabled. If latest
is disabled we will want to build master
version. Right?
readthedocs/core/views/hooks.py
Outdated
"(Version build) Building %s:%s", | ||
project.slug, slug_version.slug | ||
) | ||
return LATEST | ||
|
||
if project.versions.exclude(active=True).filter(slug=slug).exists(): |
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.
Isn't this query easily re-written as follow?
project.versions.filter(active=False, slug=slug).exists()
I found it way easier to read it.
readthedocs/core/views/hooks.py
Outdated
log.info("(Version build) Building %s:%s", | ||
project.slug, slug_version.slug) | ||
return LATEST | ||
if latest_version.active: |
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.
The case where latest
is disabled is missing.
Example:
if latest.enabled:
log.info('Building latest') # note that it's important to log first then trigger
trigger_build
else:
log.info('Not building latest because disabled')
return None
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.
note that it's important to log first then trigger
I wanna to change that, but I wasn't sure if that was on purpose 🤔
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.
The other logs do that too btw, so maybe we want to change those too
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.
Go ahead!
The idea of logging first is that if the following line fail for any reason, we miss the log and we don't know "where" it could have fail.
I removed the short circuit, added more tests and left a comment linking to #4450 |
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.
¡Me encanta!
Left a comment about a test that I'd like to have. If we already have that test, this is ready to merge to me.
Also, if you didn't do it yet, please do a small QA in your local environment to be sure that this will keep working.
default_branch = self.project.versions.get(slug='master') | ||
|
||
self.assertTrue(latest_version.active) | ||
self.assertTrue(default_branch.active) |
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.
Can you add another test (if it's not already) that test when latest
is inactive but not the default_branch
that the latest
version is not triggered for build an is not re-activated and the default_branch
is triggered?
I have tested this locally, it works. I'm not sure how to test the |
Mhr... That makes me thing "Where do we automatically mark the triggered version to be built as but that one is only for the @stsewd do you know where that is happening? That's the chunk of code that we need a test for. |
The other place I found something related is but I think it's not the place where our problem is happening. |
I'm not sure where it's happening, but maybe that's by design or something else. Either way, not sure if we can add a test for that here, it's triggered inside the mocked method, we should test that in another part, but we will testing that it activates when building (if that is by design) p: |
Wait. If we don't know where this is happening, how are we sure that this PR will fix this issue of not re-activating the Also, here #4733 (comment), you mentioned this exact behavior --now, I suppose that you knew this because of manual QA. I think this need a test because looks like a black box :) Anyway, I suppose that we can merge this PR but I'd prefer if you open a new issue for adding a test on this scenario. Looks tricky and we don't really know if this will still be present in production after merging this PR or not. |
It happens on |
Where? Can you point me the specific line? I didn't find it. |
I mean, it happens inside that, and we check |
I opened #4793 |
Looks like everyone is okay with this PR. As I understand it, this PR is just changing the webhook behavior, it doesn't solve the underlying issue that |
The version isn't reactivated here, as it doesn't hit |
I'm 👍, again, on merging this PR :) |
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.
Tests look like the behavior we want. 👍
Fixes #4672