Django-nonrel: Only part of fixture data loading in production - django

As a learning project, I am using django-nonrel with the GAE to design a site with as much data as possible about the NBA. As such, I need to prepopulate my database (I'm using the GAE-datastore) with most of the data using a fixture, as entering info for 400+ players by hand is simply unthinkable. To that end I've created a .yaml fixture with the following format (taken straight from the django docs example):
- model: players.player
pk: 1
fields:
team: 10
first_name: Jeff
last_name: Adrien
age: 25
pos: SF
gp: 8
- model: players.player
pk: 2
fields:
team: 7
first_name: Arron
last_name: Afflalo
age: 26
pos: SG
gp: 32
Unfortunately, when I run "python manage.py remote loaddata nbadata.yaml', it only loads around the first 190 players (I say around because the first time it loaded 190, the second time it loaded 186) before crapping out and giving me the following error message:
File "/usr/local/google_appengine/lib/fancy_urllib/fancy_urllib/__init__.py",
line 367, in do_open
raise url_error
URLError: <urlopen error [Errno 101] Network is unreachable>
Does anyone know what's going on, and whether there is a solution?
UPDATE: I changed the name of my .yaml file to 'initial_data.yaml' to see if the automatic load would fare better during the syncdb portion of the 'python manage.py deploy' process. I got the following result:
Running syncdb.
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 448 object(s) from 1 fixture(s)
However, when I look in the datastore, there are still only 186 players! Does anyone know what's going on??

The remote API makes an HTTP request to upload each HTTP entity. At some point, your network connection is failing, and the entire operation fails.
Can think of two solutions, but neither is particularly easy:
- Find a better internet connection.
- Patch the fixture upload code in django-nonrel to do some automatic retrying instead of failing.
I'm not certain, but I don't think syncdb really works on production, I believe it just runs against the local datastore, that's why you see that succeeding.

Related

Problem with running locally with dockers

I'm following a google video to start a google cloud project with vscode and it throws me an error and I can't solve it
this is the video just in case https://youtu.be/EtMIEtLQNa0?t=298
Starting to run the app using configuration 'Cloud Run: Run/Debug Locally' from .vscode/launch.json...
To view more detailed logs, go to Output channel : "Cloud Run: Run/Debug Locally - Detailed"
Dependency check started
Dependency check succeeded
Unpausing minikube
The minikube profile 'cloud-run-dev-internal' has been scheduled to stop automatically after exiting Cloud Code. To disable this on future deployments, set autoStop to false in your launch configuration c:\Users\Franco\Desktop\proyecto\Proyecto Agenda Web\.vscode\launch.json
Configuring minikube gcp-auth addon
Using GCP project 'proyecto-agenda-web' with minikube gcp-auth
invalid skaffold config: source: C:\Users\Franco\AppData\Local\Temp\cloud-code-cloud-run-iixzxH\skaffold.yaml, in module "proyecto-agenda-web" on line 7 column 14: source: C:\Users\Franco\AppData\Local\Temp\cloud-code-cloud-run-iixzxH\skaffold.yaml, in module "proyecto-agenda-web" on line 7 column 14: invalid image "Proyecto Agenda Web": invalid reference format
source: C:\Users\Franco\AppData\Local\Temp\cloud-code-cloud-run-iixzxH\skaffold.yaml, in module "proyecto-agenda-web" on line 7 column 14: source: C:\Users\Franco\AppData\Local\Temp\cloud-code-cloud-run-iixzxH\skaffold.yaml, in module "proyecto-agenda-web" on line 7 column 14: invalid image "Proyecto Agenda Web": invalid reference format
Skaffold exited with code 1.
Cleaning up...
Finished clean up.```
I've been searching and I can't think of a solution, any ideas?
The error is descriptive:
invalid skaffold config:
source: C:\Users\Franco\AppData\Local\Temp\cloud-code-cloud-run-iixzxH\skaffold.yaml
on line 7
column 14
invalid image "Proyecto Agenda Web"
invalid reference format
You have a folder called skaffold.yaml in that directory.
On line 7, column 14, there's probably something of the form image: Proyecto Agenda Web and Projecto Agenda Web isn't a valid container image.
These are generally of the form some-repo/some-image:some-tag.
You need to correct that. There may be subsequent errors.
I assume (!?) somewhere in the video, there are instructions that explain what value to use there.

Django Celery with Redis Issues on Digital Ocean App Platform

After quite a bit of trial and error and a step by step attempt to find solutions I thought I share the problems here and answer them myself according to what I've found. There is not too much documentation on this anywhere except small bits and pieces and this will hopefully help others in the future.
Please note that this is specific to Django, Celery, Redis and the Digital Ocean App Platform.
This is mostly about the below errors and further resulting implications:
OSError: [Errno 38] Function not implemented
and
Cannot connect to redis://......
The first error happens when you try run the celery command celery -A your_app worker --beat -l info
or similar on the App Platform. It appears that this is currently not supported on digital ocean. The second error occurs when you make a number of potential mistakes.
PART 1:
While Digital Ocean might remedy this in the future here is an approach that will offer a workaround. The problem is the not supported execution pool. Google "celery execution pools" if you want to know more and how they work. The default one is prefork. But what you need is either gevent or eventlet. I went with the former for my purposes.
Whichever you pick you will have to install it as it doesn't come with celery by default. In my case it was: pip install gevent (and don't forget adding it to your requirements as well).
Once you have that you can re-run the celery command but note that gevent and beat are not supported within a single command (will result in an error). Instead do the following:
celery -A your_app worker --pool=gevent -l info
and then separately (if you want to run beat that is) in another terminal/console
celery -A your_app beat -l info
In the first line you can also specify the concurrency like so: --concurrency=100. This is not required but useful. Read up on it what it does as that goes beyond the solution here.
PART 2:
In my specific case I've tested the above locally (development) first to make sure they work. The next issue was getting this into production. I use Redis as the db/broker.
In my specific setup I have most of my celery configuration in the_main_app/celery/__init__.py file but sometimes people put it directly into the_main_app/celery.py. Whichever it is you do make sure that the REDIS_URL is set correctly. For development it usually looks something like this:
YOUR_VAR_NAME = os.environ.get('REDIS_URL', 'redis://localhost:6379') where YOUR_VAR_NAME is then set to the broker with everything as below:
YOUR_VAR_NAME = os.environ.get('REDIS_URL', 'redis://localhost:6379')
app = Celery('the_main_app')
app.conf.broker_url = YOUR_VAR_NAME
The remaining settings are all documented on the "celery first steps with django" help page but are not relevant for what I am showing here.
PART 3:
When you setup your Redis Database on the App Platform (which is very simple) you will see the connection details as 'public network' and 'VPC network'.
The celery documentation says to use the following URL format for production: redis://:password#hostname:port/db_number. This didn't work. If you are not using a yaml file then you can simply copy paste the entire connection string (select from the dropdown!) from the Redis DB connection details and then setup an App-Level environment variable in your Digital Ocean project named REDIS_URL and paste in that entire string (and also encrypt it!).
The string should look like something like this (redis with 2 s!)
rediss://USER:PASS#URL.db.ondigitialocean.com:PORT.
You are almost done. The last step is to setup the workers. It was fine for me to run the PART 1 commands as console commands on the App Platform to test them but eventually I've setup a small worker (+ Add Component) for each line pasted them into the Run Command.
That is basically the process step by step. Good luck!

Bitnami Ghost CMS aws instance Config file is not valid JSON issue

I am setting up ghost cms on aws for a client and hit a wall. I am using the bitnami image for setting this up. I haven't touched the config file that comes default in bitnami image. Ghost is not starting up and it's showing this error in the log
Debug Information:
OS: Debian GNU/Linux, v10
Node Version: v10.20.1
Ghost-CLI Version: 1.14.0
Environment: production
Command: 'ghost log'
An error occurred.
Message: 'Cannot read property 'join' of undefined'
Stack: TypeError: Cannot read property 'join' of undefined
at instance.isRunning.then (/opt/bitnami/apps/ghost/lib/node_modules/ghost-cli/lib/commands/log.js:34:88)
at process._tickCallback (internal/process/next_tick.js:68:7)
OK it literally wasted hours of my life. And the problem was found. The reason was that in the config file the url of the blog was given as an IP address. But Ghost has said in it's setup documentation that this is likely to cause issues. So when I changed this to a URL instead of the IP address it was fixed. Hurraaay!!

"Mailgun Magnificent API" error with Django-Anymail in docker on Digital Ocean

I am running a django application running on docker
and I am using django-anymail to send emails via mailgun.
When I go through for example a forgot my password process I am getting an error in django-anymail:
AnymailRequestsAPIError: Invalid JSON in Mailgun API response
Sending a message to testemail#test.com from info#application.co.uk
Mailgun API response 200 (OK): 'Mailgun Magnificent API'
# anymail/backends/base_requests.py in deserialize_json_response at line 106
I am able to re-create this error if I docker exec -it onto the django container and run the following in a python manage.py shell
from django.core.mail import send_mail
customer_email = send_mail('Test','Test','info#*application*.co.uk',["*test#test.com*"],fail_silently=False)
If I run this after building and running my production.yml docker locally it works and I get an email but if I run this on the container on my digital ocean droplet I receive an error.
Is there a configuration I am missing in order to get this working? I have another django application just running on a droplet(no docker) and it works fine with mailgun using the same setup.
The error "Mailgun Magnificent API" is most likely caused by a # character in your MAILGUN_SENDER_DOMAIN. That often happens when you try to use line-end comments in a config file format that doesn't support them—like dotenv:
# .env
MAILGUN_SENDER_DOMAIN=mail.example.com # INVALID: dotenv doesn't allow comment here
If you upgrade to django-anymail v6.0, you'll get an improved error message that makes this more obvious.
(This answer covers other situations that can lead to "Mailgun Magnificent API.")

Issue with Heoku Postgres "could not access file “$libdir/postgis-2.1"

I have a project that works with GeoDjango, Postgis and its deploy it in Heroku.
Some info of what I'm using:
Python 2.7.15
Django 1.11.20
Heroku-18 (Stack)
Postgres 9.4.20
Postgis 2.1.8
In the last months the system threw me an error every time I want to load de geografic info, when I execute a geocode query.
ERROR: could not access file "$libdir/postgis-2.1": No such file or
directory
I have looked for the web and stackoverflow for the solutions and I found some that was really near of my problem but I tried their solutions and doesn't work for me.
I tried the "ALTER EXTENSION postgis UPDATE" solution but throw me this error:
ERROR: cannot create temporary table within security-restricted
operation
I tried the "backup your DB, Drop the local database and restaurations" but when I run the comand pg:backups:capture I get
An error occurred and the backup did not finish.
When I run the pg:backups:info
And trow me this:
2019-03-02 23:08:31 +0000 pg_dump: [archiver (db)] query failed:
ERROR: could not access file "$libdir/postgis-2.1": No such file or
directory ... (some database code) 2019-03-02 23:08:31 +0000
waiting for pg_dump to complete 2019-03-02 23:08:31 +0000 pg_dump
finished with errors
Then I found this entry
Update PostGIS extensions on Heroku
And found that it's the same problem that I have with heroku postgres, (but the author is using ruby) and the author says that was helped by the support team of Heroku. Well I create a ticket and find that "Technical support for Free applications is provided by the online community" and stackoverflow, so I tried to add a comment to this user to say samething like "hey, can you share the solution please? I have the same problem." but I haven't enough reputation to do it.
So what can I do?
I found the solution !!!
With an old db backup archive that I had, I reset the db from the heroku datastores section and after that I restored with the backup archive (with pgAdmin III) and the problem its gonne.
Its seems like the error was with postgis version, becouse when I had the problem my postgis version was 2.1.8 and now with the error solved my versión of postgis is 2.4.4.
I hope it is useful to someone.