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

24.12 Release #3021

Merged
merged 10 commits into from
Dec 31, 2024
4 changes: 4 additions & 0 deletions guide/config/en/sidebar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ root:
path: guide/advanced/versioning.html
- label: Signals
path: guide/advanced/signals.html
- label: Custom CLI Commands
path: guide/advanced/commands.html
- label: Best Practices
items:
- label: Blueprints
Expand Down Expand Up @@ -145,6 +147,8 @@ root:
items:
- label: "2024"
items:
- label: Sanic 24.12
path: release-notes/2024/v24.12.html
- label: Sanic 24.6
path: release-notes/2024/v24.6.html
- label: "2023"
Expand Down
57 changes: 57 additions & 0 deletions guide/content/en/guide/advanced/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Custom CLI Commands

.. new:: New in v24.12

This feature was added in version 24.12

Sanic ships with a [CLI](../running/running.html#running-via-command) for running the Sanic server. Sometimes, you may have the need to enhance that CLI to run your own custom commands. Commands are invoked using the following basic pattern:

```sh
sanic path.to:app exec <command> [--arg=value]
```

.. column::

To enable this, you can use your `Sanic` app instance to wrap functions that can be callable from the CLI using the `@app.command` decorator.

.. column::

```python
@app.command
async def hello(name="world"):
print(f"Hello, {name}.")
```

.. column::

Now, you can easily invoke this command using the `exec` action.

.. column::

```sh
sanic path.to:app exec hello --name=Adam
```

Command handlers can be either synchronous or asynchronous. The handler can accept any number of keyword arguments, which will be passed in from the CLI.

.. column::

By default, the name of the function will be the command name. You can override this by passing the `name` argument to the decorator.

.. column::

```python
@app.command(name="greet")
async def hello(name="world"):
print(f"Hello, {name}.")
```

```sh
sanic path.to:app exec greet --name=Adam
```

.. warning::

This feature is still in **BETA** and may change in future versions. There is no type coercion or validation on the arguments passed in from the CLI, and the CLI will ignore any return values from the command handler. Future enhancements and changes are likely.

*Added in v24.12*
6 changes: 4 additions & 2 deletions guide/content/en/organization/policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ Sanic releases a long term support release (aka "LTS") once a year in December.

| Version | Release | LTS | Supported |
|---------|------------|---------------|-----------------|
| 23.12 | 2023-12-31 | until 2025-12 | ✅ |
| 24.12 | 2024-12-31 | until 2026-12 | ✅ |
| 24.6 | 2024-06-30 | | ⚪ |
| 23.12 | 2023-12-31 | until 2025-12 | ☑️ |
| 23.6 | 2023-07-25 | | ⚪ |
| 23.3 | 2023-03-26 | | ⚪ |
| 22.12 | 2022-12-27 | until 2024-12 | ☑️ |
| 22.12 | 2022-12-27 | | ☑️ |
| 22.9 | 2022-09-29 | | ⚪ |
| 22.6 | 2022-06-30 | | ⚪ |
| 22.3 | 2022-03-31 | | ⚪ |
Expand Down
79 changes: 79 additions & 0 deletions guide/content/en/release-notes/2024/v24.12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: Version 24.12
---

# Version 24.12

.. toc::


## Introduction

This is the first release of the version 24 [release cycle](../../organization/policies.md#release-schedule). The release cadence for v24 may be slightly altered from years past. Make sure to stay up to date in the Discord server for latest updates. If you run into any issues, please raise a concern on [GitHub](https://github.com/sanic-org/sanic/issues/new/choose).

## What to know

More details in the [Changelog](../changelog.html). Notable new or breaking features, and what to upgrade:

### 👶 _BETA_ Custom CLI commands

The `sanic` CLI utility now allows for custom commands to be invoked. Commands can be added using the decorator syntax below.

```python
@app.command
async def foo(one, two: str, three: str = "..."):
logger.info(f"FOO {one=} {two=} {three=}")


@app.command
def bar():
logger.info("BAR")


@app.command(name="qqq")
async def baz():
logger.info("BAZ")
```

These are invoked using the `exec` command as follows.

```sh
sanic server:app exec <command> [--arg=value]
```

Any arguments in the function's signature will be added as arguments. For example:

```sh
sanic server:app exec command --one=1 --two=2 --three=3
```

.. warning::

This is in **BETA** and the functionality is subject to change in upcoming versions.

### Add Python 3.13 support

We have added Python 3.13 to the supported versions.

### Remove Python 3.8 support

Python 3.8 reached end-of-life. Sanic is now dropping support for Python 3.8, and requires Python 3.9 or newer.

### Old response cookie accessors removed

Prior to v23, cookies on `Response` objects were set and accessed as dictionary objects. That was deprecated in v23.3 when the new [convenience methods](../2023/v23.3.html#more-convenient-methods-for-setting-and-deleting-cookies) were added. The old patterns have been removed.

## Thank you

Thank you to everyone that participated in this release: :clap:

[@ahopkins](https://github.com/ahopkins)
[@C5H12O5](https://github.com/C5H12O5)
[@ChihweiLHBird](https://github.com/ChihweiLHBird)
[@HyperKiko](https://github.com/HyperKiko)
[@imnotjames](https://github.com/imnotjames)
[@pygeek](https://github.com/pygeek)

---

If you enjoy the project, please consider contributing. Of course we love code contributions, but we also love contributions in any form. Consider writing some documentation, showing off use cases, joining conversations and making your voice known, and if you are able: [financial contributions](https://opencollective.com/sanic-org/).
27 changes: 24 additions & 3 deletions guide/content/en/release-notes/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,32 @@ content_class: changelog
🔶 Current release
🔷 In support LTS release


## Version 24.6.0 🔶
## Version 24.12.0 🔶🔷

_Current version_

### Features
- [#3019](https://github.com/sanic-org/sanic/pull/3019) Add custom commands to `sanic` CLI

### Bugfixes
- [#2992](https://github.com/sanic-org/sanic/pull/2992) Fix `mixins.startup.serve` UnboundLocalError
- [#3000](https://github.com/sanic-org/sanic/pull/3000) Fix type annocation for `JSONResponse` method for return type `bytes` allowed for `dumps` callable
- [#3009](https://github.com/sanic-org/sanic/pull/3009) Fix `SanicException.quiet` attribute handling when set to `False`
- [#3014](https://github.com/sanic-org/sanic/pull/3014) Cleanup some typing
- [#3015](https://github.com/sanic-org/sanic/pull/3015) Kill the entire process group if applicable
- [#3016](https://github.com/sanic-org/sanic/pull/3016) Fix incompatible type annotation of get method in the HTTPMethodView class

### Deprecations and Removals
- [#3020](https://github.com/sanic-org/sanic/pull/3020) Remove Python 3.8 support

### Developer infrastructure
- [#3017](https://github.com/sanic-org/sanic/pull/3017) Cleanup setup.cfg

### Improved Documentation
- [#3007](https://github.com/sanic-org/sanic/pull/3007) Fix typo in documentation for `sanic-ext`

## Version 24.6.0

### Features
- [#2838](https://github.com/sanic-org/sanic/pull/2838) Simplify request cookies `getlist`
- [#2850](https://github.com/sanic-org/sanic/pull/2850) Unix sockets can now use `pathlib.Path`
Expand Down Expand Up @@ -193,7 +214,7 @@ From that list, the items to highlight in the release notes:
- [#2712](https://github.com/sanic-org/sanic/pull/2712) Improved example using ``'https'`` to create the redirect


## Version 22.12.0 🔷
## Version 22.12.0

_Current LTS version_

Expand Down
2 changes: 1 addition & 1 deletion sanic/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "24.6.0"
__version__ = "24.12.0"
13 changes: 1 addition & 12 deletions sanic/cookies/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any, Optional

from sanic.cookies.response import Cookie
from sanic.log import deprecation
from sanic.request.parameters import RequestParameters


Expand Down Expand Up @@ -126,21 +125,11 @@ class CookieRequestParameters(RequestParameters):
""" # noqa: E501

def __getitem__(self, key: str) -> Optional[str]:
deprecation(
f"You are accessing cookie key '{key}', which is currently in "
"compat mode returning a single cookie value. Starting in v24.9 "
"accessing a cookie value like this will return a list of values. "
"To avoid this behavior and continue accessing a single value, "
f"please upgrade from request.cookies['{key}'] to "
f"request.cookies.get('{key}'). See more details: "
"https://sanic.dev/en/guide/release-notes/v23.3.html#request-cookies", # noqa
24.9,
)
try:
value = self._get_prefixed_cookie(key)
except KeyError:
value = super().__getitem__(key)
return value[0]
return value

def __getattr__(self, key: str) -> str:
if key.startswith("_"):
Expand Down
Loading
Loading