Comment by Amir Afianian on Python TooManyRedirects: Exceeded 30 redirects
@Bridge added the source
View ArticleComment by Amir Afianian on How to delay evaluation of python expression...
Looks promising. There are more challenges to what I want though, I just revised the question. Could you have another expert look?
View ArticleComment by Amir Afianian on How to delay evaluation of python expression...
The reason I want to postpone is that the evaluation of has_perm inside auth classes depends on some runtime value (for instance some request header value). By Postpone I mean that I want the or logic...
View ArticleComment by Amir Afianian on How to delay evaluation of python expression...
Hmm, could work. But the bitwise logic will be hidden under the IsAllowed class while I want it to be exposed in its init.
View ArticleComment by Amir Afianian on How to change __init__ param before instantiation
The important difference is that I want to define the bitwise logic explicitly on IsAllowed. So it looks like: IsAllowed(IsAdmin | HasPerm)
View ArticleComment by Amir Afianian on What's the best way to create flink table for...
Yes, timestamps and values are of the same length, could you share a snippet?
View ArticleComment by Amir Afianian on How to create a refreshable table using in-memory...
@DavidAnderson is PROCESS_CONTINUOUSLY supported by pyflink?
View ArticleComment by Amir Afianian on pre-commit authenticating to gitlab
Solved the issue for me as well
View ArticleComment by Amir Afianian on Validate iso datetime of csv column pyspark
@JNevill I added the missing info. Thanx.
View ArticleAnswer by Amir Afianian for Python module does not recognize module variable
A variable is global so long as you have not assigned it a value in your function. The latter makes the variable local. Even if, like in your case, the condition is not satisfied.Note: The use of...
View ArticleAnswer by Amir Afianian for Django: Get User profile from User serializer
The easiest way is to put, for showing profile data is to put depth = 1 in class Meta of your serializer as follows:class CurrentUserSerializer(serializers.ModelSerializer): groups =...
View Articledjango, is it possible to use django multiple databases for file distribution
I have a scenario in which user uploads a file and a django app encodes the file into N distinct segments, each, to be stored on a different remote server. Say if we have 5 segments as the result of...
View ArticleAnswer by Amir Afianian for Where do I keep ORM in a distributed app?
I'd suggest you keep your DRF code with the rest of Django and containerize them together.As for the ORM, what matters is the container for Postgres. You cannot tear apart, say, models into a separate...
View ArticleAnswer by Amir Afianian for Download full text from tweepy API
You just need to pass tweet_mode='extended' while initializing Api:df = pd.DataFrame([str(tweet.created_at) +''+ tweet.text +'' for tweet in tweepy.Cursor(api.user_timeline, tweet_mode='extended', id =...
View ArticleAnswer by Amir Afianian for Google scholar blocks python scrapy with Captcha
Try using Google Cache along with a referer.Also, note not to send more than 2 requests/sec. You may get blocked:headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36...
View ArticleAnswer by Amir Afianian for Which field in Django model to choose for a file...
It's a fairly and obvious choice to make:This is what Django docs say about FilePathFieldA CharField whose choices are limited to the filenames in a certain directory on the filesystem. Has some...
View ArticleAnswer by Amir Afianian for Converting Django BooleanField to...
It's taking you so long because of this for loop: objects= MyModel.objects.active().filter(my_boolean=False) for object in objects: object.my_boolean = None object.save() # Database roundtrip Namely,...
View ArticleAnswer by Amir Afianian for Mock a subset of a Python class's methods and...
Instead of patching the whole class, you must patch the object. Namely, make an instance of your class, then, patch the methods of that instance.Note that you can also use the decorator @patch.object...
View ArticleAnswer by Amir Afianian for Why can't I install Rasa on OSX? "There was a...
Given that you're on Mac you're gonna have an easier time if you go through homebrewIf you do not have Homebrew:/usr/bin/ruby -e "$(curl -fsSL...
View ArticleAnswer by Amir Afianian for How to add data from one model to other django?
Provided that your Person model has a relation to Comment models, simply add depth = 1 in your Person serializer as follows:class PersonSerializer(serializers.ModelSerializer): user = UserSerializer()...
View ArticleHow do I retrieve a value of a field in a queryset object
I'm new to django and have the following model:class MainFile(models.Model): owner = models.ForeignKey(User) # docfile = models.FileField(verbose_name= 'Enter you file', null=True) file_id =...
View ArticleHow to Run Tests for Installed Django Apps Using Pytest
Using the traditional unit test, I can run tests for an installed Django app using the command: python manage.py test <name_of_the_installed_app>But this is not the case when using pytest as the...
View ArticleHow to instruct pip to install a requirement with --no-binary flag
I have an app that I want to package which is dependent on protobuf. It is essential that protobuf be installed as such:pip install protobuf --no-binary=protobuf protobufHow can I include this inside...
View ArticleAnswer by Amir Afianian for Sort dictionary as per length of values
Easy way if you are sure that your keys will be integers:d = {key: value for key, value in sorted(d.items())}
View ArticleAnswer by Amir Afianian for Override the third party view for end-point
You must take two steps:Step 1: Override the ConvertTokenView view to include your desired fields as such:class MyCustumConvertTokenView(CsrfExemptMixin, OAuthLibMixin, APIView):""" Implements an...
View ArticleHow to mock django settings attributes in pytest-django
When using Django default unittest it's trivial to patch settings attributes (using @override_settings decorator for instance.)I'd like to override several attributes of my settings for a test method....
View ArticleAnswer by Amir Afianian for Access different serializer if a queryset is...
This is the correct practice to change serializer class in ModelViewSet:You have to override get_serializesr_class method:class SavedVenuesViewSet(viewsets.ModelViewSet): serializer_class =...
View ArticleWhat is the best practice for keeping Kafka consumer alive in python?
Something is puzzling for me when it comes to keeping consumers alive. Let's say I have a topic to which data is constantly being written. But, in an hour in a day, there are no new messages. If I had...
View ArticleHow to write a very large json into kafka using python
I have a JSON of 4.6 GB size with the following structure:[ {...}, {...}, ...]I want a python code to read this JSON and write them into a Kafka topic with 16 partitions as much as possible.One...
View ArticleHow to change __init__ param before instantiation
I want to achieve a simple interface as such:IsAllowed(perms=[IsAdmin(runtime_value) | HasPerm('*')])Since some variables upon instantiation are not available, I have to postpone the evaluation of...
View ArticlePyFlink: What's the best way to provide reference data and keep them uptated
I have a use case where I want to do comparisons between incoming data and some reference data provided by another service.What's the best way in pyflink to fetch those data and update them regularly...
View ArticleHow do I get child process PIDs when using ProcessPoolExecuter?
I'm using ProcessPoolExecutor context manager to run several Kafka consumers in parallel. I need to store the process IDs of the child processes so that later, I can cleanly terminate those processes....
View ArticleHow to serve a created tempfile in django
I have a remote storage project that when the user requests his file, the django server retrieves and stores the file locally (for some processing) as a temporary file and then serves it to the user...
View ArticleAnswer by Amir Afianian for Path conflict between server and client
There are several things you can try1. Auto-add trailing slashMake sure 'django.middleware.common.CommonMiddleware' is within your middle_wares in settings.pyIn addition, make sure APPEND_SLASH = True...
View ArticleHow to track hierarchy of usage in pycharm
Let's say I have defined a low-level dataclass or pydantic model. What I want is to find the hierarchy of all the objects (functions, classes, etc.) that directly or indirectly depend on that model.I...
View Article