Skip to content

Commit

Permalink
Merge branch 'main' into logs-csv-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pleek91 authored Jul 22, 2024
2 parents e6d9cf9 + 43af48b commit 9b2f2ee
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 111 deletions.
74 changes: 17 additions & 57 deletions .github/ISSUE_TEMPLATE/1_bug_report.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
name: 🐛 Bug Report
description: Report a bug or unexpected behavior in Prefect
labels: ["needs:triage", "bug"]
labels: ["bug"]
body:
- type: markdown
attributes:
value: >
Bug reports are often **usage questions, not bugs**. If you do not have a strong understanding
of the interface you are reporting a bug for, please head to our [Community Slack](https://www.prefect.io/slack/)
or [Discourse](https://discourse.prefect.io/) and ask there first. You are likely to get a response
faster and learn more about the feature you're working with. If the issue is determined to be a bug,
we will open an issue here.
GitHub issues raised against this repository will receive community support. If you have an
[active support agreement](https://www.prefect.io/pricing/), we recommend creating a case to ensure
a faster response.
- type: markdown
attributes:
value: >
Expand All @@ -29,56 +16,33 @@ body:
4. Additional details that may help us reproduce your issue.
- type: checkboxes
id: checks
attributes:
label: First check
description: Please confirm and check all the following options.
options:
- label: I added a descriptive title to this issue.
required: true
- label: I used the GitHub search to find a similar issue and didn't find it.
required: true
- label: I searched the Prefect documentation for this issue.
required: true
- label: I checked that this issue is related to Prefect and not one of its dependencies.
required: true
For usage questions, please check out Prefect's [Community Slack](https://www.prefect.io/slack/).
- type: textarea
attributes:
label: Bug summary
description: A clear and concise description of what the bug is.
validations:
required: true
description: A clear and concise description of what the bug is, ideally including [a minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example).
placeholder: >
An explanation of the behavior, along with code that will help others reproduce the issue:
- type: textarea
attributes:
label: Reproduction
description: >
Provide your [minimal, complete, and verifiable](https://stackoverflow.com/help/mcve) example here.
If you need help creating one, you can model yours after the code shared in one of our previous [well written bug reports](https://github.com/PrefectHQ/prefect/issues?q=is%3Aissue+label%3A%22great+writeup%22).
placeholder: "# Insert code here"
render: python3
validations:
required: true
```python
from prefect import flow
@flow
def my_flow():
raise ValueError("This flow misbehaves every time it's run and I don't know why!")
```
Please include tracebacks, console output, etc. with code formatting.
- type: textarea
attributes:
label: Error
description: >
Provide the full exception traceback or console error.
placeholder: "# Copy complete stack trace and error message here, including log or console output if applicable."
render: python3
validations:
required: false
required: true

- type: textarea
attributes:
label: Versions (`prefect version` output)
label: Version info (`prefect version` output)
description: >
Provide information about your Prefect version and environment. The easiest way to retrieve all of the information we require is the `prefect version` command.
If using Prefect 1.x, it is useful to also include the output of `prefect diagnostics`.
**Please do not just include your Prefect version number**. The command provides additional context such as your operating system, Prefect API type, Python version, etc. that we need to diagnose your problem.
Provide information about your Prefect version and environment. The easiest way to retrieve all of this information is by running the `prefect version` command.
placeholder: "# Copy output of the `prefect version` command here. Do not just include your Prefect version number."
render: Text
validations:
Expand All @@ -90,7 +54,3 @@ body:
description: Add any other context about the problem here, including screenshots for UI issues.
validations:
required: false

- type: markdown
attributes:
value: "**Happy engineering!**"
23 changes: 3 additions & 20 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
<!--
Thanks for opening a pull request to Prefect! We've got a few requests to help us review contributions:
- Make sure that your title neatly summarizes the proposed changes.
- Provide a short overview of the change and the value it adds.
- Share an example to help us understand the change in user experience.
- Confirm that you've done common tasks so we can give a timely review.
- Review our contribution guidelines: https://docs.prefect.io/latest/contributing/overview/
Happy engineering!
Thanks for opening a pull request to Prefect!
If this is your first contribution, please make sure to review our contribution guidelines: https://docs.prefect.io/latest/contributing/overview/
-->

<!-- Include an overview here -->

### Example
<!--
Share an example of the change in action.
A code blurb is best. Changes to features should include an example that is executable by a new user.
If changing documentation, a link to a preview of the page is great.
-->
<!-- Include an overview of the proposed changes here -->

### Checklist
<!-- These boxes may be checked after opening the pull request. -->

- [ ] This pull request includes a label categorizing the change e.g. `maintenance`, `fix`, `feature`, `enhancement`, `docs`.
- [ ] This pull request references any related issue by including "closes `<link to issue>`"
<!-- If you do not have permission to add a label, a maintainer will add one for you -->
- If no issue exists and your change is not a small fix, please [create an issue](https://github.com/PrefectHQ/prefect/issues/new/choose) first.
- [ ] If this pull request adds new functionality, it includes unit tests that cover the changes
- [ ] If this pull request removes docs files, it includes redirect settings in `mint.json`.
Expand Down
7 changes: 6 additions & 1 deletion docs/3.0rc/develop/write-flows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ def model_validator(model: Model):
For example, to automatically convert an argument to a datetime object:

```python
from datetime import (
datetime,
timezone,
)
from typing import Optional

from prefect import flow
from datetime import datetime


@flow
Expand Down
36 changes: 34 additions & 2 deletions src/prefect/task_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from asyncio import CancelledError
from contextlib import ExitStack, contextmanager
from dataclasses import dataclass, field
from functools import wraps
from textwrap import dedent
from typing import (
Any,
Expand Down Expand Up @@ -393,8 +394,14 @@ def handle_success(self, result: R, transaction: Transaction) -> R:
)
transaction.stage(
terminal_state.data,
on_rollback_hooks=self.task.on_rollback_hooks,
on_commit_hooks=self.task.on_commit_hooks,
on_rollback_hooks=[
_with_transaction_hook_logging(hook, "rollback", self.logger)
for hook in self.task.on_rollback_hooks
],
on_commit_hooks=[
_with_transaction_hook_logging(hook, "commit", self.logger)
for hook in self.task.on_commit_hooks
],
)
if transaction.is_committed():
terminal_state.name = "Cached"
Expand Down Expand Up @@ -983,3 +990,28 @@ def run_task(
return run_task_async(**kwargs)
else:
return run_task_sync(**kwargs)


def _with_transaction_hook_logging(
hook: Callable[[Transaction], None],
hook_type: Literal["rollback", "commit"],
logger: logging.Logger,
) -> Callable[[Transaction], None]:
@wraps(hook)
def _hook(txn: Transaction) -> None:
hook_name = _get_hook_name(hook)
logger.info(f"Running {hook_type} hook {hook_name!r}")

try:
hook(txn)
except Exception as exc:
logger.error(
f"An error was encountered while running {hook_type} hook {hook_name!r}",
)
raise exc
else:
logger.info(
f"{hook_type.capitalize()} hook {hook_name!r} finished running successfully"
)

return _hook
33 changes: 2 additions & 31 deletions src/prefect/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
)
from prefect.utilities.asyncutils import run_coro_as_sync
from prefect.utilities.collections import AutoEnum
from prefect.utilities.engine import _get_hook_name


class IsolationLevel(AutoEnum):
Expand Down Expand Up @@ -180,39 +179,20 @@ def commit(self) -> bool:
return False

try:
hook_name = None

for child in self.children:
child.commit()

for hook in self.on_commit_hooks:
hook_name = _get_hook_name(hook)
if self.logger:
self.logger.info(f"Running commit hook {hook_name!r}")

hook(self)

if self.logger:
self.logger.info(
f"Commit hook {hook_name!r} finished running successfully"
)

if self.store and self.key:
self.store.write(key=self.key, value=self._staged_value)
self.state = TransactionState.COMMITTED
return True
except Exception:
if self.logger:
if hook_name:
msg = (
f"An error was encountered while running commit hook {hook_name!r}",
)
else:
msg = (
f"An error was encountered while committing transaction {self.key!r}",
)
self.logger.exception(
msg,
f"An error was encountered while committing transaction {self.key!r}",
exc_info=True,
)
self.rollback()
Expand Down Expand Up @@ -242,17 +222,8 @@ def rollback(self) -> bool:

try:
for hook in reversed(self.on_rollback_hooks):
hook_name = _get_hook_name(hook)
if self.logger:
self.logger.info(f"Running rollback hook {hook_name!r}")

hook(self)

if self.logger:
self.logger.info(
f"Rollback hook {hook_name!r} finished running successfully"
)

self.state = TransactionState.ROLLED_BACK

for child in reversed(self.children):
Expand All @@ -262,7 +233,7 @@ def rollback(self) -> bool:
except Exception:
if self.logger:
self.logger.exception(
f"An error was encountered while running rollback hook {hook_name!r}",
f"An error was encountered while rolling back transaction {self.key!r}",
exc_info=True,
)
return False
Expand Down

0 comments on commit 9b2f2ee

Please sign in to comment.