User Attribute-Based Authorization in Multitenant Apps - Django-tenants

This article assumes you’re using django-tenants for schema-based multitenancy (separate PostgreSQL schema per tenant). The authorization pattern described here works specifically with django-tenants’ schema_context() approach. If you’re curious, read the AWS cognito part as well. The Problem When building a multitenant application with django-tenants, we needed to control which PostgreSQL schema each user could access. Each tenant has its own isolated schema, but we needed a lightweight authorization mechanism to ensure users could only access their assigned tenant’s data. ...

April 15, 2025 · 6 min · Ben Shaji

Python - A Clean Way to Traverse Nested Dict/List

I had to work with some complex structured JSON responses having multiple levels of nesting. The issue has always been that the API would return nested JSON where I have to walk different levels to get data by using x.get('y')[0].get... chains. For this very reason, I was looking for an optimal and efficient solution so that at least I can avoid calling get() many times. The Problem Let’s say you’re working with user data from an API: ...

August 28, 2024 · 3 min · Ben Shaji

Global variables in AWS Lambda are dirty!

What is this post about? Today, as usual, I started off the job in the morning. I’m at a juncture point of building part of a project – we need yet another micro-service. So I started writing a Python script to be deployed in AWS Lambda. This usually takes a couple of hours, max. But after I wrote it, I realized half the time was spent debugging an issue I didn’t even understand. ...

November 1, 2023 · 4 min · Ben Shaji