[Ironpython-users] IronPython query to Windows Azure Table Storage

Cory Brostowicz dj_grafix at hotmail.com
Mon Jul 15 20:21:34 CEST 2013


In an application I'm working on, I'm trying to write an IronPython script that queries Azure Tables, returning a result into a class defined in Python.  I keep running into the following error when I do this:
Unhandled Exception: System.InvalidOperationException: The type 'IronPython.NewTypes.IPAzureTest.BaseModelClass_1$1' is not supported by the client library.   at System.Data.Services.Client.ClientType.Create(Type type, Boolean expectModelType)   at System.Data.Services.Client.AtomMaterializer.ResolveByCreating(AtomEntry entry, Type expectedEntryType)   at System.Data.Services.Client.AtomMaterializer.ResolveOrCreateInstance(AtomEntry entry, Type expectedEntryType)   at System.Data.Services.Client.AtomMaterializerInvoker.DirectMaterializePlan(Object materializer, Object entry, Type expectedEntryType)   at System.Data.Services.Client.ProjectionPlan.Run(AtomMaterializer materializer, AtomEntry entry, Type expectedType)   at System.Data.Services.Client.AtomMaterializer.Read()   at System.Data.Services.Client.MaterializeAtom.MoveNextInternal()   at System.Data.Services.Client.MaterializeAtom.MoveNext()   at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)   at System.Data.Services.Client.DataServiceQueryProvider.ReturnSingleton[TElement](Expression expression)   at System.Data.Services.Client.DataServiceQueryProvider.Execute[TResult](Expression expression)   at System.Linq.Queryable.Single[TSource](IQueryable`1 source)   at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)   at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)   at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)   at IPAzureTest.IPScriptHost.RunEdit() in d:\Development\Utilities\IPAzureTest\IPAzureTest\IPScriptHost.cs:line 31   at IPAzureTest.Program.Main(String[] args) in d:\Development\Utilities\IPAzureTest\IPAzureTest\Program.cs:line 12

If I define the model class in C#, I do not run into this issue.  The data I'm working with changes often.  Being able to define the model in Python will make it so new builds are not necessary when additional tables are added.  
Here is what my python script looks like:
import clrimport Systemclr.AddReference("System.Core")clr.ImportExtensions(System.Linq)
class MyTable(AzureTableService.BaseModelClass):	def __new__(self, partitionKey, rowKey):		self.PartitionKey = partitionKey		self.RowKey = rowKey		return super.__new__(self)			MyTableDetails = "";
y = AzureTableService.GetAzureTableQuery[MyTable]("MyTable")z = y.Where(lambda c: c.PartitionKey == "10" and c.RowKey == "10040").Single()
print(z.MyTableDetails)
And my C# Code:
    public class AzureTableService {
        private CloudStorageAccount mStorageAccount;
        public AzureTableService() {
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) => {
                var connectionString = ConfigurationManager.AppSettings[configName];
                configSetter(connectionString);
            });
            mStorageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");        
        }
                
        private TableServiceContext AzureTableServiceContext {
            get {
                var context = mStorageAccount.CreateCloudTableClient().GetDataServiceContext();
                context.IgnoreResourceNotFoundException = true;
                return context;
            }
        }
        public IQueryable<T> GetAzureTableQuery<T>(string TableName) {
            return AzureTableServiceContext.CreateQuery<T>(TableName);
        }
 
        public class BaseModelClass : TableServiceEntity {
            public BaseModelClass(string partitionKey, string rowKey) : base(partitionKey, rowKey) { }
            public BaseModelClass() : base(Guid.NewGuid().ToString(), String.Empty) { }
        }
 
        public class MyTable : TableServiceEntity {
            public MyTable(string partitionKey, string rowKey) : base(partitionKey, rowKey) { }
            public MyTable() : base(Guid.NewGuid().ToString(), String.Empty) { }
            public string FeeScheduleDetails { get; set; }
        }
    }
If I use MyTable define in C#, it works fine.  By using the one defined in Python throws the exception.  Can anyone point me in the right direction?
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20130715/2445c522/attachment.html>


More information about the Ironpython-users mailing list