Create Geodatabase Connection mishandles escape characters

2350
10
Jump to solution
05-11-2016 11:51 AM
ShaneBuscher
Occasional Contributor

The Create Geodatabase Connection fails when passing an instance parameter containing escape characters. For instance, passing 'nomsqapp4d\nomsqapp4d' fails because the '\n' is interpreted inside the arcpy tool code as a new line. This can be verified by calling the function via Python and through running the tool itself in ArcGIS Desktop.

Note that the example instance name is a standard company format and can't be changed. Is there any way around this issue or should this be logged as a bug?

1 Solution

Accepted Solutions
ChristianWells
Esri Contributor

Does a capital 'N' work? Other tools have had this problem too, such as the Create Database user tool, where DOMAIN\tim doesn't work properly. However, I found that switching the value to a capital letter, allowed me to move forward, as \n or \t is an escape but not \T or \N. In reviewing the current defects within Esri Technical Support, the following defect sounds like the issue: NIM082676 - Unexpected behavior occurs when using input parame..

But as Joshua Bixby​ said, please log an Esri Technical Support case so we can attach you to this defect.

View solution in original post

10 Replies
DanPatterson_Retired
MVP Esteemed Contributor

you have to use 'raw' notation

notice the difference that the 'r' makes to how a string is handled in printing and backslashes are handled

>>> a = 'nomsqapp4d\nomsqapp4d'
>>> b = r'nomsqapp4d\nomsqapp4d'
>>> a
'nomsqapp4d\nomsqapp4d'
>>> b
'nomsqapp4d\\nomsqapp4d'
>>> print(a)
nomsqapp4d
omsqapp4d
>>> print(b)
nomsqapp4d\nomsqapp4d
ShaneBuscher
Occasional Contributor

Unfortunately that has been tried without success. The correct db instance value is being passed into Create Geodatabase Connection function. The heart of the issue is the function internally converts nomsqapp4d\nomsqapp4d to a string with a line feed, which I have no control over.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Interesting, I see the same thing with some dummy connections I just made.  This is definitely a bug, I encourage you to contact Esri Support.

I tried numerous "workarounds" and found something completely ugly that works, i.e., double up the backslash and 'n' when using raw strings:

r'nomsqapp4d\\nnomsqapp4d'

WesMiller
Regular Contributor III

Have you tried

import os
path = os.path.normpath('nomsqapp4d\nomsqapp4d')
path
'nomsqapp4d\nomsqapp4d'
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

This isn't a Python problem, it is a problem with the tool itself, i.e., generating a valid string isn't the problem, getting the tool to use the valid string is the problem.

ChristianWells
Esri Contributor

Does a capital 'N' work? Other tools have had this problem too, such as the Create Database user tool, where DOMAIN\tim doesn't work properly. However, I found that switching the value to a capital letter, allowed me to move forward, as \n or \t is an escape but not \T or \N. In reviewing the current defects within Esri Technical Support, the following defect sounds like the issue: NIM082676 - Unexpected behavior occurs when using input parame..

But as Joshua Bixby​ said, please log an Esri Technical Support case so we can attach you to this defect.

DanPatterson_Retired
MVP Esteemed Contributor

raw formatting... \t ... arcpy hmmmm https://community.esri.com/message/608012#comment-608012

two does not make a trend I hope?

ShaneBuscher
Occasional Contributor

Thanks Christian for the workaround and Dan for the ESRI bug reference. Using all caps does the trick.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

We should all get used to the workaround because if the bug hasn't been touched in 4 years, I doubt it will miraculously get addressed anytime soon.

0 Kudos