PythonForEver

Python

Room rules: sopython.com/chatroom Code formatting guide: tinyu...
Nov 27 07:13
Oddly, some of the tests did find the files, while others didn't. I guess I should organize it all and post it as a question in SO. Thanks so far. You were all very helpful.
Nov 27 07:12
@roganjosh Ah, yes. I use docker.
Nov 26 06:12
@roganjosh perhaps I misunderstood but, the opt traceback is from the local environment (Pycharm). In general the mock-files are not created on the fly; they exist alongside the rest of the code (containing the unit-tests) and are committed together with it.
Nov 26 06:09
@IlyaEgorov you are right. .resolve(strict) raises an error in the pipelines. FileNotFoundError: [Errno 2] No such file or directory: 'tests/group_a while locally is OK.
Nov 25 08:34
@roganjosh in my short Azure experience, I've found a lot of bugs and lack of features (from constant timeouts on loading their portal Defender for Cloud to no multiline logging to Container App replicas max set to 1000 by default!!).
Nov 23 15:42
(please ignore the missing _ in my project; I edit them since I can't show the exact project I work on :P )
Nov 23 15:39
> E ValueError: [PosixPath('/opt/project/my project/tests/group_a/mock_files/normal.txt'), '/opt/project/my_project']
Nov 23 15:39
^ This is when run in Azure DevOps.
When ran locally I get this:
Nov 23 15:38
> E ValueError: [PosixPath('/home/vsts/work/1/s/my_project/tests/group_a/mock_files/normal.txt'), '/home/vsts/work/1/s/my_project']
Nov 23 15:38
@roganjosh yes. All files are inside the repo. I used raise ValueError([MOCK_FILE.resolve(), os.getcwd()]) inside the test and I get:
Nov 23 10:05
(can't edit the code... it's supposed to be MOCK_FILE = MOCK_FILE_DIR / 'normal.txt', sorry)
Nov 23 10:04
My tests run locally just fine.
But in the Azure DevOps pipelines they fail with:
> FileNotFoundError: [Errno 2] No such file or directory

What am I doing wrong?
Nov 23 10:02
from pathlib import Path


MOCK_FILE_DIR = Path('tests/group_a/mock_files/')
MOCK_FILE = FAKE_TOURS_DIR / 'normal.txt'

def test_something():
    # code here...
    pass
Aug 13 17:27
I wonder if browsers do some magic and decide on their own (ignoring media_type; nah that sounds unlikely).
Aug 13 17:26
no worries.
It's so strange though, cause I can see the `content-type: text/plain; charset=ISO-8859-1` in both Postman and Firefox and Chrome.
Aug 13 17:19
I don't know if Content-Encoding is applicable in my case. I m not using any compression.
Aug 13 17:00
I'm not that familiar with encoding either :P but will eventually figure it out. Thanks anyway :)
Aug 13 16:59
I'm using media_type = f"text/plain; charset={encoding}" and "Content-Disposition": f'attachment; filename="my_file.txt"
Aug 13 16:45
I thought everyone loves it. (as in, being automatic "documentation" of an API)
Aug 13 16:44
Interesting. Why is that?
Aug 13 16:41
I use both :P
FastAPI creates the API schema when I run my containers. Then I play with the OpenAPI schema (formerly known as Swagger)
Aug 13 16:39
Here's how it looks. image
Aug 13 16:38
FastAPI uses OpenAPI to automatically generate my API in a browser-usable form. (can be achieved with DRF as well, with 3rd party libraries)
Aug 13 16:27
When downloading a file from postman i get correct encoding (windows-1252). While OpenAPI returns UTF-8 (and it's corrupted).

Why do they handle the same endpoint differently?
I even get the exact same response headers.
May 31 09:54
Pandas? :P
Had a similar issue and was wondering if it would be faster + less error prone. But my usecase includes plenty of col,row manipulation.
May 31 09:45
I ve heard of serverless run-away costs that have reached $75,000 in 2 hours. Due to bugs.
May 31 09:45
Is there a maximum of how much an Azure Function App can charge in 1 day?
Mar 26 12:57
But then again, I don't want to use a bad design just because Azure doesn't handle multiline logging well.
Mar 26 12:55
For example my task processes a user request to fetch an item that doesn't exist.
Should I raise?
The issue is that this produces a lot of repetitive logs in Azure (and it costs a lot of $)
Mar 26 12:51
Should Celery tasks raise if e.g. processing invalid user input?
Is it good practice?
Feb 1 06:42
Or perhaps even add it to my CI/CD
Feb 1 06:42
I like PyCharm's "Code Inspection".
Is it based on some free tool which I can use on its own?
Jan 2 08:44
fastAPI uses pydantic's `BaseSettings` to validate env vars when loading them.
The benefit: fails early if anything's wrong.

Does DRF have a similar built-in validator?
Dec 19, 2023 10:15
I mean in Azure. My guess is that it does, but not that experienced with either Celery or Django.
Dec 19, 2023 10:12
Does my Celery container need the same env vars as my Django container?
Sep 5, 2023 10:24
Also, I was wondering why doesn't DRF have something to import instead of using magic strings (list, retrieve, etc) when checking the permissions: if view.action in ('list', 'retrieve'). E.g. from drf.actions import LIST where LIST = 'list'
Sep 5, 2023 10:22
class MyPermission(BasePermission):
    def has_permission(self, request: Request, view: ViewSet) -> bool:
Sep 5, 2023 10:22
Is this the right way to typehint DRF Permissions?
Sep 4, 2023 09:38
@roganjosh for example a user registers with A[email protected] and tries to login with a[email protected]
Sep 4, 2023 09:34
@MisterMiyagi wow that's so much more intricate than I thought
Sep 4, 2023 08:36
That's the best practice in DRF or FastAPI (postgres+sqlalchemy) when handling emails. I mean I need to ignore case. So how do I validate-store them?
Aug 25, 2023 07:35
Interestingly enough I've heard from other devs that they rarely see PUT, and only see PATCH (instead of PUT) in some APIs. I guess it varies quite a bit per project.
Aug 25, 2023 05:36
I think it's PATCH since it partially updates one field of Users. But I m not sure. Since it does create a new row in the intermediate table.
Aug 25, 2023 05:33
I have Users and Groups tables (many-to-many). I ll create an endpoint for adding a User to a Group. Should it be POST or PATCH?
Aug 16, 2023 13:11
Seeing OpenTelemetry for Azure isn't finished yet, should I use it? Anyone had any unsolvable issues with it (with DRF or FastAPI microservices)?
Jul 26, 2023 14:07
No problem :)
Jul 26, 2023 13:53
You can press Shift shift and write "theme". Then click on it. Does it contain your theme?
Jul 26, 2023 13:52
You mean darcula?
Jul 26, 2023 12:39
Which logging library would you suggest for distributed logging (FastAPI + DRF with Azure)?
Jul 13, 2023 12:31
perhaps the APIs they worked on in the past years had issues.