MariaDB Error Using pymysql in AirFlow - sqlalchemy

Trying airflow with MariaDB and got the following sql error: I tried almost the same thing in my test.py and it works. Don't know how airflow handles this. Any tip? Airflow v1.7.1.3.
sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'default'', 3, 'BashOperator', NULL)' at line 1") [SQL: u'INSERT INTO task_instance (task_id, dag_id, execution_date, start_date, end_date, duration, state, try_number, hostname, unixname, job_id, pool, queue, priority_weight, operator, queued_dttm) VALUES (%(task_id)s, %(dag_id)s, %(execution_date)s, %(start_date)s, %(end_date)s, %(duration)s, %(state)s, %(try_number)s, %(hostname)s, %(unixname)s, %(job_id)s, %(pool)s, %(queue)s, %(priority_weight)s, %(operator)s, %(queued_dttm)s)'] [parameters: {'execution_date': datetime.datetime(2017, 10, 31, 0, 0), 'end_date': None, 'job_id': '43', 'task_id': 'print_date', 'pool': None, 'unixname': 'nrsapp', 'queued_dttm': None, 'try_number': 1, 'queue': 'default', 'operator': 'BashOperator', 'state': u'running', 'start_date': datetime.datetime(2017, 11, 3, 17, 53, 46, 178764), 'duration': None, 'priority_weight': 3, 'hostname': 'zlt11238', 'dag_id': 'tutorial'}]

Related

You have an error in your SQL syntax when using docker exec rest api

I try to run a mysql statement via docker exec api -> https://docs.docker.com/engine/api/v1.41/#operation/ContainerExec
My Statement looks like this
{
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"DetachKeys": "ctrl-p,ctrl-q",
"Tty": false,
"Cmd": [
"bin/bash","-c", "mysql -uroot -ptesttest -e 'INSERT INTO `mandator_1`.`terminal` (`serialNumber`, `name`, `isActive`, `status`, `profileId`, `businessId`, `divisionId`, `ipAddress`, `groupId`, `setupVersion`, `macAddress`, `authType`) VALUES ('54321', '54321', '1', NULL, '1', '1', NULL, '172.45.17.197', '1', NULL, 'E4-F1-D3-FD', '2');' mandator_1"
]
}
but when i run the statement i get an error
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.17.197, 1, NULL, E4-F1-D3-FD, 2)' at line 1
i think my escaping is wrong but at which point?
Try to change quote by double quote:
VALUES (\"54321\", \"54321\", \"1\", ...., \"2\");

PythonAnywhere SQLite/SQLAlchemy suddenly getting errors

SQLAlchemy and SQLite errors appearing on PythonAnywhere but it was fine on localhost.
So I just uploaded my Flask site to pythonanywhere, and when I tried to access it it can't access my database, but is getting a bunch of errors instead.
2021-01-30 10:42:05,740: Exception on /m/550 [GET]
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 580, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: near "(": syntax error
**NO MATCH**
I was not getting these exceptions on my local computer. A little googling and it seems like this is because PA uses an older version of SQLite? Which seems a bit stupid to begin with but it also seems like I can't update it?
So I'm wondering if there is some smart solution to this, or if it would perhaps be easier to switch to MySQL? Would there be other problems in doing that instead? Or do I just need to switch out the SQLALCHEMY_DATABASE_URI to fit MySQL instead? My Current one looks like this:
SQLALCHEMY_DATABASE_URI = 'sqlite:////home/movieelo/cinelow/my_server/database/database.db'
SQLALCHEMY_TRACK_MODIFICATIONS = False
All help and guidence will be greatly appreciated!
UPDATE:
I managed to switch to MySQL but am still getting SQL syntax related errors, such as:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near '(PARTITION BY
movie_category_scores.category_id ORDER BY movie_category_scores.s' at line 2
**NO MATCH**
UPDATE 2
I think that I have now identiefied the single function that is causing the errors, and it looks like this:
def get_top_movies_by_category(category_id):
query = db.session.query(
MovieCategoryScores,
func.rank()\
.over(
order_by=MovieCategoryScores.score.desc(),
partition_by=MovieCategoryScores.category_id,
)\
.label('rank')
).filter(MovieCategoryScores.votes >= 10)
# now filter
query = query.filter(MovieCategoryScores.category_id == category_id)
query = query.order_by(MovieCategoryScores.category_id, 'rank')
movies = query.all()
return movies
Which generates this error:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 580, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: near "(": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/movieelo/cinelow/my_server/database/pers_movie_dbf.py", line 137, in get_top_movies_by_category
movies = query.all()
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3186, in all
return list(self)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3342, in __iter__
return self._execute_and_instances(context)
File "/usr/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3367, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 988, in execute
return meth(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 287, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1101, in _execute_clauseelement
ret = self._execute_context(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1252, in _execute_context
self._handle_dbapi_exception(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1473, in _handle_dbapi_exception
util.raise_from_cause(sqlalchemy_exception, exc_info)
File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 152, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 580, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near "(": syntax error
[SQL: SELECT movie_category_scores.votes >= ? AS anon_1, movie_category_scores.movie_id AS movie_category_scores_movie_id, movie_category_scores.category_id AS movie_category_scores_category_id, movie_category_scores.score AS movie_category_scores_score, movie_category_scores.votes AS movie_category_scores_votes, rank() OVER (PARTITION BY movie_category_scores.category_id ORDER BY movie_category_scores.score DESC) AS rank
FROM movie_category_scores
WHERE movie_category_scores.votes >= ? AND movie_category_scores.category_id = ? ORDER BY movie_category_scores.category_id, rank]
[parameters: (10, 10, 11)]
(Background on this error at: http://sqlalche.me/e/e3q8)
Giles Thomas (of PythonAnywhere) confirmed that the SQLite version available on PythonAnywhere doesn't support window functions.
Window functions were added to SQLite version 3.25.0. In the future, you can check whether the SQLite version included with your Python installation supports windows functions by running:
import sqlite3
if sqlite3.sqlite_version_info > (3, 25, 0):
print("Window functions are supported!")
else:
print("Window functions are not supported :(")

Exception while taking backup in couchbase using cbbackup

When I'm trying to take data backup from couchbase VM using the below command
cbbackup -v http://...:8091 /opt/couchbase/backup -u Administrator -p ******. I'm getting the below error.
2018-10-22 07:13:01,647: mt cbbackup...
2018-10-22 07:13:01,648: mt source : http://**.***.**.***:8091
2018-10-22 07:13:01,648: mt sink : /opt/couchbase/backup
2018-10-22 07:13:01,648: mt opts : {'username': '<xxx>', 'verbose': 1, 'extra':
{'max_retry': 10.0, 'rehash': 0.0, 'dcp_consumer_queue_length': 1000.0, 'data_only': 0.0, 'uncompress': 0.0, 'nmv_retry': 1.0, 'conflict_resolve': 1.0, 'cbb_max_mb': 100000.0, 'report': 5.0, 'mcd_compatible': 1.0, 'try_xwm': 1.0, 'backoff_cap': 10.0, 'batch_max_bytes': 400000.0, 'report_full': 2000.0, 'flow_control': 1.0, 'batch_max_size': 1000.0, 'seqno': 0.0, 'design_doc_only': 0.0, 'allow_recovery_vb_remap': 0.0, 'recv_min_bytes': 4096.0}
, 'collection': None, 'ssl': False, 'threads': 4, 'key': None, 'password': '<xxx>', 'id': None, 'bucket_source': None, 'silent': False, 'dry_run': False, 'single_node': False, 'vbucket_list': None, 'separator': '::', 'mode': 'diff'}
2018-10-22 07:13:01,655: mt Starting new HTTP connection (1): *********
2018-10-22 07:13:01,662: mt bucket: sample_bucket
Exception in thread s3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self._target(*self.args, **self._kwargs)
File "/opt/couchbase/lib/python/pump_bfd.py", line 646, in run
return self.future_done(future, rv)
UnboundLocalError: local variable 'future' referenced before assignment
I'm using couchbase EE 5.1.1
I'm getting the above error. Any suggestions?
Use cbbackupmgr instead for EE
I ended up reading the documentation and found out for Enterprise edition there's backup manger "cbbackupmgr" which is faster more efficient than cbbackup and cbrestore.
All it requires is to first configure an empty directory as backup directory. For more information pls read the link below.https://docs.couchbase.com/server/5.5/backup-restore/cbbackupmgr-tutorial.html

Exception with cbrestore on mac OS X

I am using Couchbase Server 4.5.1.
I am trying to cbrestore a bucket, which has been backed up with cbbackup on Ubuntu, and I am getting the following exception:
/Applications/Couchbase\ Server.app/Contents/Resources/couchbase-core/bin/cbrestore . http://localhost:8091 -u Administrator -p st0ryplAyr --bucket-source=storyplayer-api --bucket-destination=storyplayer-api -v -x rehash=1
2017-06-27 09:51:02,610: mt cbrestore...
2017-06-27 09:51:02,610: mt source : .
2017-06-27 09:51:02,610: mt sink : http://localhost:8091
2017-06-27 09:51:02,610: mt opts : {'username': '<xxx>', 'verbose': 1, 'extra': {'max_retry': 10.0, 'rehash': 1.0, 'dcp_consumer_queue_length': 1000.0, 'data_only': 0.0, 'uncompress': 0.0, 'nmv_retry': 1.0, 'conflict_resolve': 1.0, 'cbb_max_mb': 100000.0, 'report': 5.0, 'mcd_compatible': 1.0, 'try_xwm': 1.0, 'backoff_cap': 10.0, 'batch_max_bytes': 400000.0, 'report_full': 2000.0, 'flow_control': 1.0, 'batch_max_size': 1000.0, 'seqno': 0.0, 'design_doc_only': 0.0, 'recv_min_bytes': 4096.0}, 'ssl': False, 'threads': 4, 'to_date': None, 'key': None, 'password': '<xxx>', 'id': None, 'bucket_source': 'storyplayer-api', 'silent': False, 'dry_run': False, 'from_date': None, 'bucket_destination': 'storyplayer-api', 'add': False, 'vbucket_list': None}
2017-06-27 09:51:02,615: mt bucket: storyplayer-api
Exception in thread s0:
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/Applications/Couchbase Server.app/Contents/Resources/couchbase-core/lib/python/pump_mc.py", line 91, in run
rv, batch, need_backoff = self.scatter_gather(mconns, batch)
File "/Applications/Couchbase Server.app/Contents/Resources/couchbase-core/lib/python/pump_cb.py", line 72, in scatter_gather
rv, conn = self.find_conn(mconns, vbucket_id, msgs)
File "/Applications/Couchbase Server.app/Contents/Resources/couchbase-core/lib/python/pump_cb.py", line 316, in find_conn
host_port = serverList[vBucketMap[vbucket_id][0]]
IndexError: list index out of range
I had the same error (or comparable) previously which is why I am using the option rehash=1 but this time it does not help.
Any idea about what I could do?
I'm a little bit late to answer this question, but you have to add "-x rehash=1" to your command:
cbrestore ~/backups http://127.0.0.1:8091 -u Administrator -p password -x rehash=1
There reason why is that Couchbase has 1024 vbuckets on most operational systems, but on Mac there are just 64 vBuckets (for optmization purposes ), so you need to rehash to redistribute the data between all vbuckets

1290 Error on Google Cloud SQL

I just started getting this Error today while using MySQL workbench, and noticed it showing up in my application as far back as saturday. Anyone else getting it?
Have any idea what might be causing it?
ERROR
Error Code: 1290. The MySQL server is running with the --read-only option so it cannot execute this statement
Running just a simple insert generates the error. Eg..
INSERT INTO Job1111.SubsWeld
(fk_SubmissionId, WeldSpool1, WeldSpool2, WeldDrawingNumber, WeldLineNumber, WeldSheetNumber, WeldTimeInForm, WeldLineSpec, WeldNumber, WeldStencil, WeldSize, WeldThickness, WeldType, WeldPosition, WeldMaterial, WeldProcedure, WeldComplete, WeldShared, WeldPercentCompleted, WeldRework, ActivityType, Rev)
VALUES ('66', '5990-363-A', '5990-363-B', 'V-0020-3', '12-V-0020', '3', '0', 'A', '1059', '1059', '24.00', 'Sch. 40', 'BW', '5G', 'CS', '1013 Rev2', '1', '0', '100', '0', '22', '0');